Skip to content

Commit

Permalink
add activate flag to install command
Browse files Browse the repository at this point in the history
  • Loading branch information
MrLYC committed Dec 27, 2021
1 parent 458a596 commit 0293080
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cmd/command/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ import (
"github.com/mrlyc/cmdr/utils"
)

var installCmdFlag struct {
activate bool
}

// installCmd represents the install command
var installCmd = &cobra.Command{
Use: "install",
Short: "Install command into cmdr",
Run: func(cmd *cobra.Command, args []string) {
binDir := core.GetBinDir()
shimsDir := core.GetShimsDir()

runner := core.NewStepRunner(
Expand All @@ -22,6 +27,14 @@ var installCmd = &cobra.Command{
core.NewBinariesInstaller(shimsDir),
)

if installCmdFlag.activate {
runner.Add(
core.NewCommandDeactivator(),
core.NewBinariesActivator(binDir, shimsDir),
core.NewCommandActivator(),
)
}

utils.ExitWithError(runner.Run(cmd.Context()), "install failed")

define.Logger.Info("installed command", map[string]interface{}{
Expand All @@ -39,6 +52,7 @@ func init() {
flags.StringVarP(&simpleCmdFlag.name, "name", "n", "", "command name")
flags.StringVarP(&simpleCmdFlag.version, "version", "v", "", "command version")
flags.StringVarP(&simpleCmdFlag.location, "location", "l", "", "command location")
flags.BoolVarP(&installCmdFlag.activate, "activate", "a", false, "activate command")

installCmd.MarkFlagRequired("name")
installCmd.MarkFlagRequired("version")
Expand Down

0 comments on commit 0293080

Please sign in to comment.