提交 a132ab2a 编写于 作者: M Mislav Marohnić

Process `--noop` separately from `slurpGlobalFlags()`

This relieves `slurpGlobalFlags` of having too many duties
上级 c2d5e719
...@@ -168,7 +168,8 @@ func NewArgs(args []string) *Args { ...@@ -168,7 +168,8 @@ func NewArgs(args []string) *Args {
globalFlags []string globalFlags []string
) )
slurpGlobalFlags(&args, &globalFlags, &noop) slurpGlobalFlags(&args, &globalFlags)
noop = removeValue(&globalFlags, "--noop")
if len(args) == 0 { if len(args) == 0 {
params = []string{} params = []string{}
...@@ -188,7 +189,7 @@ func NewArgs(args []string) *Args { ...@@ -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 slurpNextValue := false
commandIndex := 0 commandIndex := 0
...@@ -208,15 +209,8 @@ func slurpGlobalFlags(args *[]string, globalFlags *[]string, noop *bool) { ...@@ -208,15 +209,8 @@ func slurpGlobalFlags(args *[]string, globalFlags *[]string, noop *bool) {
if commandIndex > 0 { if commandIndex > 0 {
aa := *args aa := *args
*globalFlags = aa[0:commandIndex]
*args = aa[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) { ...@@ -230,3 +224,16 @@ func removeItem(slice []string, index int) (newSlice []string, item string) {
return newSlice, item 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
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册