Skip to content

Commit

Permalink
feat(rollback): implement rollback command
Browse files Browse the repository at this point in the history
closes #19
  • Loading branch information
Irineu333 committed Jan 29, 2024
1 parent 84d4d54 commit 40c13d8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/kotlin/com/neo/envmanager/Envm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Envm : CliktCommand(
Rename(),
Setter(),
Remove(),
Rollback()
)
}

Expand Down
31 changes: 31 additions & 0 deletions src/main/kotlin/com/neo/envmanager/command/Rollback.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.neo.envmanager.command

import com.github.ajalt.clikt.parameters.options.option
import com.neo.envmanager.core.Command
import com.neo.envmanager.exception.error.SpecifyEnvironmentError
import com.neo.envmanager.model.Environment
import com.neo.envmanager.model.Target
import com.neo.envmanager.util.extension.requireInstall

class Rollback : Command(
help = "Rollback the target"
) {

private val tag by option(
names = arrayOf("-t", "--tag"),
help = "Environment tag"
)

override fun run() {

val config = requireInstall()

val target = Target.getOrCreate(config.targetPath)

val tag = tag ?: config.currentEnv ?: throw SpecifyEnvironmentError()

val environment = Environment.get(paths.environmentsDir, tag)

target.write(environment.read().toProperties())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ fun CliktCommand.requireInstall(): Config {
if (!paths.isInstalled()) {

echoFormattedHelp(NotInstalledError())

echo(Instructions.INSTALL)

throw Abort()
Expand Down

0 comments on commit 40c13d8

Please sign in to comment.