Skip to content

Commit

Permalink
Add feature to unset multiple commands at once
Browse files Browse the repository at this point in the history
Allow multiple command names to be passed to unset.

Each command name will be processed in sequence, if not found, a failure
to remove message will be printed and the action will continue.

rel: #144
  • Loading branch information
boonwj committed Sep 26, 2019
1 parent 32331d4 commit 73a17d0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cmd/unset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ For example:
1build unset test
This will update the current project configuration file.`,
Args: cobra.ExactArgs(1),
Args: cobra.MinimumNArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
_, err := config.LoadOneBuildConfiguration()
if err != nil {
Expand All @@ -38,21 +38,21 @@ This will update the current project configuration file.`,
}
},
Run: func(cmd *cobra.Command, args []string) {
commandName := args[0]

configuration, err := config.LoadOneBuildConfiguration()
if err != nil {
utils.PrintErr(err)
return
}

index := indexOfCommandIfPresent(configuration, commandName)
if index == -1 {
utils.Println("Command '" + commandName + "' not found")
return
for _, commandName := range args {
index := indexOfCommandIfPresent(configuration, commandName)
if index == -1 {
utils.Println("Command '" + commandName + "' not found")
} else {
configuration.Commands = removeCommandByIndex(configuration, index)
}
}

configuration.Commands = removeCommandByIndex(configuration, index)
_ = config.WriteConfigFile(configuration)
},
}
Expand Down

0 comments on commit 73a17d0

Please sign in to comment.