diff --git a/src/main/kotlin/com/neo/envmanager/Envm.kt b/src/main/kotlin/com/neo/envmanager/Envm.kt index db703fb..9406309 100644 --- a/src/main/kotlin/com/neo/envmanager/Envm.kt +++ b/src/main/kotlin/com/neo/envmanager/Envm.kt @@ -47,7 +47,8 @@ class Envm : CliktCommand( Rename(), Setter(), Remove(), - Rollback() + Rollback(), + Copy() ) } diff --git a/src/main/kotlin/com/neo/envmanager/command/Copy.kt b/src/main/kotlin/com/neo/envmanager/command/Copy.kt new file mode 100644 index 0000000..a8a31e4 --- /dev/null +++ b/src/main/kotlin/com/neo/envmanager/command/Copy.kt @@ -0,0 +1,28 @@ +package com.neo.envmanager.command + +import com.github.ajalt.clikt.parameters.arguments.argument +import com.neo.envmanager.core.Command +import com.neo.envmanager.model.Environment +import com.neo.envmanager.util.extension.requireInstall + +class Copy : Command( + help = "Copy an environment" +) { + private val tag by argument( + help = "Environment tag" + ) + + private val newTag by argument( + help = "New environment tag" + ) + + override fun run() { + + requireInstall() + + Environment.get( + paths.environmentsDir, + tag + ).copyTo(newTag) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/neo/envmanager/command/Rename.kt b/src/main/kotlin/com/neo/envmanager/command/Rename.kt index 204a5d3..ab4f95f 100644 --- a/src/main/kotlin/com/neo/envmanager/command/Rename.kt +++ b/src/main/kotlin/com/neo/envmanager/command/Rename.kt @@ -10,8 +10,8 @@ class Rename : Command( help = "Rename an environment" ) { - private val oldTag by argument( - help = "Old environment tag" + private val tag by argument( + help = "Environment tag" ) private val newTag by argument( @@ -22,9 +22,12 @@ class Rename : Command( val config = requireInstall() - Environment.get(paths.environmentsDir, oldTag).renameTo(newTag) + Environment.get( + paths.environmentsDir, + tag + ).renameTo(newTag) - if (oldTag == config.currentEnv) { + if (tag == config.currentEnv) { config.update { it.copy( currentEnv = newTag diff --git a/src/main/kotlin/com/neo/envmanager/model/Environment.kt b/src/main/kotlin/com/neo/envmanager/model/Environment.kt index d410042..a9f5bf6 100644 --- a/src/main/kotlin/com/neo/envmanager/model/Environment.kt +++ b/src/main/kotlin/com/neo/envmanager/model/Environment.kt @@ -37,6 +37,17 @@ value class Environment(val file: File) { return Environment(newFile) } + fun copyTo(tag: String) : Environment { + + val newFile = file.parentFile.resolve(tag.json) + + if (newFile.exists()) throw EnvironmentAlreadyExists(tag) + + file.copyTo(newFile) + + return Environment(newFile) + } + fun add(properties: Map<*, *>) { write(read() + properties) }