diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..ad84532
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/README-PT.md b/README-PT.md
deleted file mode 100644
index c60162d..0000000
--- a/README-PT.md
+++ /dev/null
@@ -1,149 +0,0 @@
-[english](README.md) | **português**
-
-# EnvManager
-
-Controle facilmente as propriedades do seu ambiente.
-
-### Instalação
-
-Para instalar, baixe o arquivo de instalação disponível em [releases](https://github.com/Irineu333/EnvManager/releases),
-extraia e execute `install.sh` (Linux) com permissões de administrador. Para informações mais detalhadas consulte
-as [instruções de instalação](src/dist/INSTALLATION).
-
-> **Compatibilidade:** GNU/Linux, Termux
-
-### Funcionamento
-
-O **EnvManager** é ideal para projetos com **múltiplos ambientes**, onde as variáveis são gerenciadas por um **arquivo
-de propriedades** (denominado **target**) no formato `chave=valor`. Com o **EnvManager**, você pode alternar entre
-diferentes ambientes e realizar outras manipulações **diretamente do terminal**.
-
-### Uso
-
-Após a instalação, o **EnvManager** é acessado pelo comando `envm`, seguido de um comando e seus argumentos.
-
-``` shell
-$ envm [options] [arguments]
-```
-
-> **Opções:** --path=\, --version, --show-config
-
-Você pode obter as instruções de qualquer comando a opção `--help`.
-
-``` shell
-$ envm --help
-```
-
-[Mais informações](docs/portuguese/envm.md)
-
-### Comandos Essenciais
-
-Esses comandos cobrem as principais funcionalidades para uso diário.
-
-#### install
-
-Inicialize o **EnvManager** no diretório do seu projeto com o comando `install`.
-
-``` shell
-$ envm install
-```
-
-> **Opções:** --target=\, --force
-
-[Mais detalhes](docs/portuguese/install.md)
-
-#### save
-
-Salve as propriedades atuais como um ambiente usando `save`, seguido do nome do ambiente (denominado **tag**).
-
-``` shell
-$ envm save
-```
-
-> **Opções:** --clipboard
-
-[Mais detalhes](docs/portuguese/save.md)
-
-#### list
-
-Liste os ambientes salvos com o comando `list`.
-
-``` shell
-$ envm list
-```
-
-Para listar propriedades de um ambiente específico, adicione a **tag** após o comando.
-
-``` shell
-$ envm list
-```
-
-> **Opções:** --current, --target
-
-[Mais detalhes](docs/portuguese/list.md)
-
-#### checkout
-
-Mude para um ambiente diferente com `checkout`.
-
-``` shell
-$ envm checkout
-```
-
-> **Opções:** --force
-
-[Mais detalhes](docs/portuguese/checkout.md)
-
-#### delete
-
-Exclua um ou mais ambientes com `delete`.
-
-``` shell
-$ envm delete
-```
-
-> **Opções:** --all
-
-[Mais detalhes](docs/portuguese/delete.md)
-
-### Outros Comandos
-
-#### set
-
-Adicione ou modifique propriedades com `set`.
-
-``` shell
-$ envm set
-```
-
-> **Opções:** --tag=\, --all, --target-only
-
-[Mais detalhes](docs/portuguese/set.md)
-
-#### remove
-
-Remova propriedades específicas com `remove`.
-
-``` shell
-$ envm remove
-```
-
-> **Opções:** --tag=\, --all, --target-only
-
-[Mais detalhes](docs/portuguese/remove.md)
-
-#### rename
-
-Renomeie um ambiente com `rename`.
-
-``` shell
-$ envm rename
-```
-
-#### rollback
-
-Reverta alterações no **target**, sincronizando com o ambiente atual, usando `rollback`.
-
-``` shell
-$ envm rollback
-```
\ No newline at end of file
diff --git a/README.md b/README.md
index 3249d5b..ad22161 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,3 @@
-**english** | [português](README-PT.md)
-
# EnvManager
Easily control your environment properties.
@@ -34,7 +32,7 @@ You can get the instructions for any command with the `--help` option.
$ envm --help
```
-[More information](docs/english/envm.md)
+[More information](docs/envm.md)
### Essential Commands
@@ -50,7 +48,7 @@ $ envm install
> **Options:** --target=, --force
-[More details](docs/english/install.md)
+[More details](docs/install.md)
#### save
@@ -62,7 +60,7 @@ $ envm save
> **Options:** --clipboard
-[More details](docs/english/save.md)
+[More details](docs/save.md)
#### list
@@ -80,7 +78,7 @@ $ envm list
> **Options:** --current, --target
-[More details](docs/english/list.md)
+[More details](docs/list.md)
#### checkout
@@ -92,7 +90,7 @@ $ envm checkout
> **Options:** --force
-[More details](docs/english/checkout.md)
+[More details](docs/checkout.md)
#### delete
@@ -104,7 +102,7 @@ $ envm delete
> **Options:** --all
-[More details](docs/english/delete.md)
+[More details](docs/delete.md)
### Other Commands
@@ -118,7 +116,7 @@ $ envm set
> **Options:** --tag=, --all, --target-only
-[More details](docs/english/set.md)
+[More details](docs/set.md)
#### remove
@@ -130,7 +128,7 @@ $ envm remove
> **Options:** --tag=, --all, --target-only
-[More details](docs/english/remove.md)
+[More details](docs/remove.md)
#### rename
@@ -148,5 +146,6 @@ Revert changes in the **target**, synchronizing with the current environment, us
$ envm rollback
```
----
-Translated from [README-PT.md](README-PT.md) using [ChatGPT](https://chat.openai.com/share/9d76f100-2955-4e01-b5d9-5dc10ee9b6de)
\ No newline at end of file
+### Others commands
+
+See the documentation for the other commands at [docs](/docs).
\ No newline at end of file
diff --git a/build.gradle.kts b/build.gradle.kts
index aae5f6d..1e7a8c3 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -6,7 +6,7 @@ plugins {
}
group = "com.neo.envmanager"
-version = "1.0.0"
+version = "1.1.0"
repositories {
mavenCentral()
diff --git a/docs/english/checkout.md b/docs/checkout.md
similarity index 100%
rename from docs/english/checkout.md
rename to docs/checkout.md
diff --git a/docs/english/delete.md b/docs/delete.md
similarity index 100%
rename from docs/english/delete.md
rename to docs/delete.md
diff --git a/docs/english/envm.md b/docs/envm.md
similarity index 100%
rename from docs/english/envm.md
rename to docs/envm.md
diff --git a/docs/export.md b/docs/export.md
new file mode 100644
index 0000000..b398805
--- /dev/null
+++ b/docs/export.md
@@ -0,0 +1,26 @@
+# `export` command
+
+Use the `export` command to export environments to a `.envm` file.
+
+**Export all environments:**
+
+```shell
+$ envm export
+```
+
+**Export specific tags:**
+
+```shell
+$ envm export
+```
+> **Note:** You can export multiple environments by separating the tags with a space.
+
+## Options
+
+### `--output`
+
+Specify the output directory of the environments file; if not specified, will be prompt for it during export.
+
+```shell
+$ envm export --output=
+```
\ No newline at end of file
diff --git a/docs/import.md b/docs/import.md
new file mode 100644
index 0000000..69feccd
--- /dev/null
+++ b/docs/import.md
@@ -0,0 +1,7 @@
+# `import` command
+
+Use the `import` command to import environments from a `.envm` file.
+
+```shell
+$ envm import
+```
\ No newline at end of file
diff --git a/docs/english/install.md b/docs/install.md
similarity index 96%
rename from docs/english/install.md
rename to docs/install.md
index ea65ec6..3736ac5 100644
--- a/docs/english/install.md
+++ b/docs/install.md
@@ -8,7 +8,7 @@ $ envm install [options]
## Options
-### `--target` or `-t`
+### `--target`
Sets the path of the target properties file (`target`). If not specified, **EnvManager** will prompt for it during installation.
diff --git a/docs/english/list.md b/docs/list.md
similarity index 100%
rename from docs/english/list.md
rename to docs/list.md
diff --git a/docs/portuguese/checkout.md b/docs/portuguese/checkout.md
deleted file mode 100644
index a0ca01b..0000000
--- a/docs/portuguese/checkout.md
+++ /dev/null
@@ -1,23 +0,0 @@
-# Comando `checkout`
-
-Use o comando `checkout` para alternar entre os ambientes.
-
-```shell
-$ envm checkout
-```
-
-Também pode ser usado para para criar um ambientes vazio utilizando a opção `-force`.
-
-```shell
-$ envm checkout -force
-```
-
-## Opção
-
-### `-force` ou `-f`
-
-Força o checkout, criando um ambiente se não existir.
-
-```shell
-$ envm checkout -force
-```
\ No newline at end of file
diff --git a/docs/portuguese/delete.md b/docs/portuguese/delete.md
deleted file mode 100644
index d3501ee..0000000
--- a/docs/portuguese/delete.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# Comando `delete`
-
-Use o comando `delete` para excluir um ou mais ambientes.
-
-**Deletando um ambiente:**
-
-``` shell
-$ envm delete
-```
-**Deletando vários ambientes:**
-
-``` shell
-$ envm delete ... [opções]
-```
-
-## Opções
-
-### `--all` ou `-a`
-Exclua todos os ambientes.
\ No newline at end of file
diff --git a/docs/portuguese/envm.md b/docs/portuguese/envm.md
deleted file mode 100644
index e0a5731..0000000
--- a/docs/portuguese/envm.md
+++ /dev/null
@@ -1,30 +0,0 @@
-# Comando `envm`
-
-É o ponto central do **EnvManager**`, permitindo o acesso a todos os outros comandos disponíveis.
-
-```shell
-$ envm [opções] [argumentos do comando]
-```
-
-## Opções
-
-### `--path` ou `-p`
-Especifica o caminho do projeto onde o **EnvManager** está ou será instalado. O diretório atual é usado por padrão.
-
-```shell
-$ envm --path=/projects/MyProject
-```
-
-### `--version` ou `-v`
-Mostra a versão atual do **EnvManager**.
-
-```shell
-$ envm --version
-```
-
-### `--show-config` ou `-c`
-Exibe as informações do arquivo de configuração do **EnvManager**.
-
-```shell
-$ envm --show-config
-```
diff --git a/docs/portuguese/install.md b/docs/portuguese/install.md
deleted file mode 100644
index 45bd311..0000000
--- a/docs/portuguese/install.md
+++ /dev/null
@@ -1,25 +0,0 @@
-# Comando `install`
-
-Use o comando `install` para inicializar o **EnvManager** em um diretório. Necessário para usar os demais comandos.
-
-```shell
-$ envm install [opções]
-```
-
-## Opções
-
-### `--target` ou `-t`
-
-Define o caminho do arquivo de propriedades alvo (`target`). Se não especificado, o **EnvManager** solicitará durante a instalação.
-
-```shell
-$ envm install --target=environment.properties
-```
-
-### `--force` ou `-f`
-
-Força a instalação do **EnvManager**, mesmo que um arquivo de configuração já esteja presente no diretório. Essa opção é útil para resolver problemas na instalação.
-
-```shell
-$ envm install --force
-```
\ No newline at end of file
diff --git a/docs/portuguese/list.md b/docs/portuguese/list.md
deleted file mode 100644
index 3ec6f84..0000000
--- a/docs/portuguese/list.md
+++ /dev/null
@@ -1,31 +0,0 @@
-# Comando `list`
-
-Use o comando `list` para exibir os ambientes salvos ou as propriedades de um ambiente específico.
-
-**Para listar todos os ambientes salvos:**
-
-```shell
-$ envm list
-```
-
-**Para listar as propriedades de um ambiente específico:**
-
-```shell
-$ envm list
-```
-
-## Opções
-
-### `--current` ou `-c`
-Mostra as propriedades do ambiente atual, facilitando a visualização rápida da configuração em uso.
-
-```shell
-$ envm list --current
-```
-
-### `--target` ou `-t`
-Exibe as propriedades do arquivo de propriedades alvo (**target**).
-
-```shell
-$ envm list --target
-```
\ No newline at end of file
diff --git a/docs/portuguese/remove.md b/docs/portuguese/remove.md
deleted file mode 100644
index cecf73f..0000000
--- a/docs/portuguese/remove.md
+++ /dev/null
@@ -1,48 +0,0 @@
-# Comando `remove`
-
-Use o comando `remove` para excluir propriedades especificadas pelas suas chaves.
-
-**Para excluir uma única propriedade:**
-
-```shell
-$ envm remove [opções]
-```
-
-**Para excluir múltiplas propriedades:**
-
-```shell
-$ envm remove ... [opções]
-```
-
-## Opções
-
-### `--tag` ou `-t`
-Especifica o ambiente alvo. Na ausência desta opção, o ambiente atual é utilizado.
-
-```shell
-$ envm remove --tag=
-```
-
-### `--all` ou `-a`
-Esta opção tem dois comportamentos, dependendo da presença de chaves:
-
-**Com chaves especificadas:**
-Remove as chaves fornecidas de todos os ambientes salvos.
-
- ```shell
- $ envm remove --all
- ```
-
-**Sem chaves especificadas:**
-Exclui todas as propriedades do ambiente atual (ou especificado via `--tag`).
-
- ```shell
- $ envm remove --all
- ```
-
-### `--target-only` ou `-o`
-Restringe a remoção às chaves apenas ao arquivo de propriedades alvo (**target**), sem impactar os ambientes salvos.
-
-```shell
-$ envm remove --target-only
-```
\ No newline at end of file
diff --git a/docs/portuguese/rename.md b/docs/portuguese/rename.md
deleted file mode 100644
index 88e4341..0000000
--- a/docs/portuguese/rename.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# Comando `rename`
-
-Renomeia um ambiente.
-
-``` shell
-$ envm rename
-```
\ No newline at end of file
diff --git a/docs/portuguese/rollback.md b/docs/portuguese/rollback.md
deleted file mode 100644
index 985e5eb..0000000
--- a/docs/portuguese/rollback.md
+++ /dev/null
@@ -1,7 +0,0 @@
-# Comando `rollback`
-
-Reverta as propriedades do **target** para o estado do ambiente atual.
-
-``` shell
-$ envm rollback
-```
\ No newline at end of file
diff --git a/docs/portuguese/save.md b/docs/portuguese/save.md
deleted file mode 100644
index 6de2c43..0000000
--- a/docs/portuguese/save.md
+++ /dev/null
@@ -1,24 +0,0 @@
-# Comando `save`
-
-Use o comando `save` para savar as propriedades do arquivo de propriedades alvo (**target**) no ambiente atual ou em um ambiente especificado após o comando.
-
-**Para salvar no ambiente atual:**
-
-```shell
-$ envm save [opções]
-```
-
-**Para salvar em um ambiente específico:**
-
-```shell
-$ envm save [opções]
-```
-
-## Opções
-
-### `--clipboard` ou `-c`
-Captura as propriedades da área de transferência em vez de usar o arquivo **target**.
-
-```shell
-$ envm save --clipboard
-```
\ No newline at end of file
diff --git a/docs/portuguese/set.md b/docs/portuguese/set.md
deleted file mode 100644
index aff5c9b..0000000
--- a/docs/portuguese/set.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# Comando `set`
-
-Use para adicionar ou modificar propriedades `set`. Você deve fornecer as propriedades no formato `chave=valor`, separadas por espaço.
-
-**Para definir uma única propriedade:**
-
-```shell
-$ envm set KEY1=VALUE [opções]
-```
-
-**Para definir múltiplas propriedades simultaneamente:**
-
-```shell
-$ envm set KEY1=VALUE1 KEY2=VALUE2 ... [opções]
-```
-
-## Opções
-
-### `--tag` ou `-t`
-Permite especificar o ambiente alvo para as propriedades. Na ausência desta opção, o ambiente atual é utilizado.
-
-```shell
-$ envm set --tag=
-```
-
-### `--all` ou `-a`
-Aplica as propriedades fornecidas a todos os ambientes salvos, facilitando a sincronização de configurações entre diferentes contextos.
-
-```shell
-$ envm set --all
-```
-
-### `--target-only` ou `-o`
-Limita a adição ou modificação de propriedades ao arquivo de propriedades alvo (**target**), sem afetar as configurações dos ambientes salvos. Isso é útil para modificações temporárias.
-
-```shell
-$ envm set --target-only
-```
\ No newline at end of file
diff --git a/docs/english/remove.md b/docs/remove.md
similarity index 98%
rename from docs/english/remove.md
rename to docs/remove.md
index 3c40429..c269dc1 100644
--- a/docs/english/remove.md
+++ b/docs/remove.md
@@ -16,7 +16,7 @@ $ envm remove ... [options]
## Options
-### `--tag` or `-t`
+### `--tag`
Specifies the target environment. In the absence of this option, the current environment is used.
```shell
diff --git a/docs/english/rename.md b/docs/rename.md
similarity index 100%
rename from docs/english/rename.md
rename to docs/rename.md
diff --git a/docs/english/rollback.md b/docs/rollback.md
similarity index 100%
rename from docs/english/rollback.md
rename to docs/rollback.md
diff --git a/docs/english/save.md b/docs/save.md
similarity index 100%
rename from docs/english/save.md
rename to docs/save.md
diff --git a/docs/english/set.md b/docs/set.md
similarity index 98%
rename from docs/english/set.md
rename to docs/set.md
index 8f52bc3..2a7021c 100644
--- a/docs/english/set.md
+++ b/docs/set.md
@@ -16,7 +16,7 @@ $ envm set KEY1=VALUE1 KEY2=VALUE2 ... [options]
## Options
-### `--tag` or `-t`
+### `--tag`
Allows specifying the target environment for the properties. In the absence of this option, the current environment is used.
```shell
diff --git a/src/main/kotlin/com/neo/envmanager/Envm.kt b/src/main/kotlin/com/neo/envmanager/Envm.kt
index 1d20cef..6245dc5 100644
--- a/src/main/kotlin/com/neo/envmanager/Envm.kt
+++ b/src/main/kotlin/com/neo/envmanager/Envm.kt
@@ -7,7 +7,6 @@ import com.github.ajalt.clikt.parameters.options.default
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.clikt.parameters.types.file
-import com.github.ajalt.mordant.rendering.TextStyle
import com.github.ajalt.mordant.rendering.TextStyles
import com.neo.envmanager.command.*
import com.neo.envmanager.model.Paths
@@ -49,7 +48,9 @@ class Envm : CliktCommand(
Rename(),
Setter(),
Remove(),
- Rollback()
+ Rollback(),
+ Export(),
+ Import()
)
}
@@ -66,14 +67,18 @@ class Envm : CliktCommand(
private fun printConfigAndExit() {
- val config = requireInstall()
+ val installation = requireInstall()
+ val config = installation.config
val dim = TextStyles.dim
- val stringBuilder = StringBuilder("target: ${dim(config.targetPath)}")
+ val message = buildString {
- config.currentEnv?.let { stringBuilder.append("\ncurrent: ${dim(it)}") }
+ append("target: ${dim(config.targetPath)}")
- throw PrintCompletionMessage(stringBuilder.toString())
+ config.currentEnv?.let { append("\ncurrent: ${dim(it)}") }
+ }
+
+ throw PrintCompletionMessage(message)
}
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/neo/envmanager/command/Checkout.kt b/src/main/kotlin/com/neo/envmanager/command/Checkout.kt
index af0df0e..98881d8 100644
--- a/src/main/kotlin/com/neo/envmanager/command/Checkout.kt
+++ b/src/main/kotlin/com/neo/envmanager/command/Checkout.kt
@@ -1,15 +1,15 @@
package com.neo.envmanager.command
+import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.neo.envmanager.com.neo.envmanager.util.extension.update
-import com.neo.envmanager.core.Command
import com.neo.envmanager.model.Environment
import com.neo.envmanager.model.Target
import com.neo.envmanager.util.extension.requireInstall
import com.neo.envmanager.util.extension.tag
-class Checkout : Command(
+class Checkout : CliktCommand(
help = "Checkout an environment"
) {
@@ -22,12 +22,20 @@ class Checkout : Command(
override fun run() {
- val config = requireInstall()
+ val installation = requireInstall()
+
+ val config = installation.config
val target = Target.getOrCreate(config.targetPath)
+ val environment = if (force) {
+ Environment.getOrCreate(installation.environmentsDir, tag)
+ } else {
+ Environment(installation.environmentsDir, tag)
+ }
+
target.write(
- getEnvironment()
+ environment
.read()
.toProperties()
)
@@ -38,13 +46,4 @@ class Checkout : Command(
)
}
}
-
- private fun getEnvironment(): Environment {
-
- return if (force) {
- Environment.getOrCreate(paths.environmentsDir, tag)
- } else {
- Environment(paths.environmentsDir, tag)
- }
- }
}
\ No newline at end of file
diff --git a/src/main/kotlin/com/neo/envmanager/command/Delete.kt b/src/main/kotlin/com/neo/envmanager/command/Delete.kt
index c9bf849..4e0804c 100644
--- a/src/main/kotlin/com/neo/envmanager/command/Delete.kt
+++ b/src/main/kotlin/com/neo/envmanager/command/Delete.kt
@@ -1,6 +1,7 @@
package com.neo.envmanager.command
import com.github.ajalt.clikt.core.Abort
+import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.terminal
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.arguments.multiple
@@ -8,18 +9,18 @@ import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import com.github.ajalt.mordant.terminal.YesNoPrompt
import com.neo.envmanager.com.neo.envmanager.util.extension.update
-import com.neo.envmanager.core.Command
import com.neo.envmanager.exception.Cancel
+import com.neo.envmanager.exception.error.NoEnvironmentsFound
import com.neo.envmanager.exception.error.SpecifyEnvironmentError
-import com.neo.envmanager.model.Config
import com.neo.envmanager.model.Environment
-import com.neo.envmanager.util.extension.deleteChildren
+import com.neo.envmanager.model.Installation
+import com.neo.envmanager.util.Constants
import com.neo.envmanager.util.extension.requireInstall
import com.neo.envmanager.util.extension.success
import extension.getOrNull
import extension.ifFailure
-class Delete : Command(
+class Delete : CliktCommand(
help = "Delete one or more environments"
) {
@@ -32,11 +33,11 @@ class Delete : Command(
help = "Delete all environments"
).flag()
- private lateinit var config: Config
+ private lateinit var installation: Installation
override fun run() {
- config = requireInstall()
+ installation = requireInstall()
if (all) {
deleteAll()
@@ -54,7 +55,7 @@ class Delete : Command(
val environments = tags.mapNotNull { tag ->
Environment.getSafe(
- dir = paths.environmentsDir,
+ dir = installation.environmentsDir,
tag = tag
).ifFailure {
echoFormattedHelp(error = it)
@@ -65,7 +66,7 @@ class Delete : Command(
environments.forEach { it.file.delete() }
- val currentTag = config.currentEnv ?: return
+ val currentTag = installation.config.currentEnv ?: return
val currentHasDeleted = environments.any {
it.file.nameWithoutExtension == currentTag
@@ -78,11 +79,15 @@ class Delete : Command(
private fun deleteAll() {
- val count = paths.environmentsDir.listFiles()?.size ?: 0
+ val environments = installation.environmentsDir.listFiles { _, name ->
+ name.endsWith(Constants.DOT_JSON)
+ } ?: throw NoEnvironmentsFound()
- if (YesNoPrompt("Delete all $count environment?", terminal).ask() != true) throw Cancel()
+ val mustDeleteMessage = "Delete all ${environments.size} environment?"
- paths.environmentsDir.deleteChildren()
+ if (YesNoPrompt(mustDeleteMessage, terminal).ask() != true) throw Cancel()
+
+ environments.forEach { it.delete() }
clearCurrentEnvironment()
@@ -90,7 +95,7 @@ class Delete : Command(
}
private fun clearCurrentEnvironment() {
- config.update {
+ installation.config.update {
it.copy(
currentEnv = null
)
diff --git a/src/main/kotlin/com/neo/envmanager/command/Export.kt b/src/main/kotlin/com/neo/envmanager/command/Export.kt
new file mode 100644
index 0000000..b0bba3a
--- /dev/null
+++ b/src/main/kotlin/com/neo/envmanager/command/Export.kt
@@ -0,0 +1,124 @@
+package com.neo.envmanager.command
+
+import com.github.ajalt.clikt.core.Abort
+import com.github.ajalt.clikt.core.CliktCommand
+import com.github.ajalt.clikt.core.terminal
+import com.github.ajalt.clikt.parameters.arguments.argument
+import com.github.ajalt.clikt.parameters.arguments.multiple
+import com.github.ajalt.clikt.parameters.options.defaultLazy
+import com.github.ajalt.clikt.parameters.options.option
+import com.github.ajalt.clikt.parameters.types.file
+import com.github.ajalt.mordant.terminal.YesNoPrompt
+import com.neo.envmanager.com.neo.envmanager.util.NotBlankValidation
+import com.neo.envmanager.com.neo.envmanager.util.extension.environments
+import com.neo.envmanager.exception.error.NoEnvironmentsFound
+import com.neo.envmanager.model.Environment
+import com.neo.envmanager.model.Installation
+import com.neo.envmanager.model.Target
+import com.neo.envmanager.util.extension.envm
+import com.neo.envmanager.util.extension.promptFile
+import com.neo.envmanager.util.extension.requireInstall
+import com.neo.envmanager.util.extension.resolveCollision
+import com.neo.envmanager.util.gson
+import java.io.File
+
+class Export : CliktCommand(
+ help = "Export environments"
+) {
+
+ private val output by option(
+ names = arrayOf("--output"),
+ help = "Output directory"
+ ).file(
+ canBeDir = true,
+ canBeFile = false
+ ).defaultLazy {
+ terminal.promptFile(
+ text = "Output directory",
+ canBeDir = true,
+ canBeFile = false,
+ default = File("output")
+ )
+ }
+
+ private val tags by argument(
+ help = "Specific tag (optional"
+ ).multiple()
+
+ private lateinit var installation: Installation
+
+ override fun run() {
+
+ installation = requireInstall()
+
+ if (!output.exists()) {
+
+ echo("Output directory '${output.path}' does not exist.")
+
+ if (YesNoPrompt("Create it?", terminal).ask() != true) throw Abort()
+
+ output.mkdirs()
+ }
+
+ if (tags.isEmpty()) {
+ exportAllEnvironments()
+ return
+ }
+
+ exportSpecificEnvironment()
+ }
+
+ private fun exportAllEnvironments() {
+
+ val environments = installation.environments()
+
+ if (environments.isEmpty()) {
+ throw NoEnvironmentsFound()
+ }
+
+ writeExportFile(environments)
+ }
+
+ private fun exportSpecificEnvironment() {
+
+ val environments = tags.map {
+ Environment(installation.environmentsDir, it)
+ }
+
+ writeExportFile(environments)
+ }
+
+ private fun writeExportFile(
+ environments: List
+ ) {
+ val name = when {
+ environments.size == 1 -> {
+ environments.single().tag
+ }
+
+ tags.isEmpty() -> {
+ Target(installation.config.targetPath).name
+ }
+
+ else -> {
+ checkNotNull(
+ terminal.prompt(
+ prompt = "Choose a name for the export file",
+ convert = NotBlankValidation
+ )
+ )
+ }
+ }
+
+ output.resolve(name.envm).resolveCollision().writeText(
+ gson.toJson(
+ buildMap {
+ environments.forEach {
+ put(it.tag, it.read())
+ }
+ }
+ )
+ )
+ }
+}
+
diff --git a/src/main/kotlin/com/neo/envmanager/command/Import.kt b/src/main/kotlin/com/neo/envmanager/command/Import.kt
new file mode 100644
index 0000000..4819fc8
--- /dev/null
+++ b/src/main/kotlin/com/neo/envmanager/command/Import.kt
@@ -0,0 +1,53 @@
+package com.neo.envmanager.command
+
+import com.github.ajalt.clikt.core.CliktCommand
+import com.github.ajalt.clikt.core.terminal
+import com.github.ajalt.clikt.parameters.arguments.argument
+import com.github.ajalt.clikt.parameters.arguments.validate
+import com.github.ajalt.clikt.parameters.types.file
+import com.github.ajalt.mordant.terminal.YesNoPrompt
+import com.neo.envmanager.com.neo.envmanager.util.EnvironmentsFileValidation
+import com.neo.envmanager.model.Environment
+import com.neo.envmanager.model.FilePromise
+import com.neo.envmanager.util.Constants
+import com.neo.envmanager.util.MapTypeToken
+import com.neo.envmanager.util.extension.requireInstall
+import com.neo.envmanager.util.gson
+
+class Import : CliktCommand(
+ help = "Import environments"
+) {
+
+ private val file by argument(
+ help = "Environment(s) file (${Constants.DOT_ENVM})"
+ ).file(
+ mustExist = true,
+ canBeDir = false,
+ canBeFile = true
+ ).validate(EnvironmentsFileValidation)
+
+ override fun run() {
+
+ val installation = requireInstall()
+
+ val type = MapTypeToken>().type
+
+ val environments = gson.fromJson