diff --git a/commands/args.go b/commands/args.go index 5f82345eb1b0aac2638e55d9699bd1e5db2691b7..3df3b69dcef483e275bf8cd28be2b7b7a7b8a398 100644 --- a/commands/args.go +++ b/commands/args.go @@ -168,7 +168,8 @@ func NewArgs(args []string) *Args { globalFlags []string ) - slurpGlobalFlags(&args, &globalFlags, &noop) + slurpGlobalFlags(&args, &globalFlags) + noop = removeValue(&globalFlags, "--noop") if len(args) == 0 { params = []string{} @@ -188,7 +189,7 @@ func NewArgs(args []string) *Args { } } -func slurpGlobalFlags(args *[]string, globalFlags *[]string, noop *bool) { +func slurpGlobalFlags(args *[]string, globalFlags *[]string) { slurpNextValue := false commandIndex := 0 @@ -208,15 +209,8 @@ func slurpGlobalFlags(args *[]string, globalFlags *[]string, noop *bool) { if commandIndex > 0 { aa := *args + *globalFlags = aa[0:commandIndex] *args = aa[commandIndex:] - - for _, arg := range aa[0:commandIndex] { - if arg == "--noop" { - *noop = true - } else { - *globalFlags = append(*globalFlags, arg) - } - } } } @@ -230,3 +224,16 @@ func removeItem(slice []string, index int) (newSlice []string, item string) { return newSlice, item } + +func removeValue(slice *[]string, value string) (found bool) { + var newSlice []string + for _, item := range *slice { + if item == value { + found = true + } else { + newSlice = append(newSlice, item) + } + } + *slice = newSlice + return found +}