checkpoint

This commit is contained in:
Lynn Cyrin 2019-08-26 00:18:36 -07:00
parent 406a1c31b0
commit 2071bcfb83
No known key found for this signature in database
GPG Key ID: EE9CCB427DFEC897

View File

@ -214,14 +214,18 @@ func (c *Command) useShortOptionHandling() bool {
return c.UseShortOptionHandling return c.UseShortOptionHandling
} }
// reorderArgs moves all flags (reorderedFlags) before arguments (remainingArgs) // reorderArgs moves all flags (via reorderedArgs) before the rest of
// as this is what flag expects. // the arguments (remainingArgs) as this is what flag expects.
func reorderArgs(commandFlags []Flag, args []string) []string { func reorderArgs(commandFlags []Flag, args []string) []string {
var remainingArgs []string var remainingArgs []string
var reorderedFlags []string var reorderedArgs []string
readFlagValue := false readFlagValue := false
for i, arg := range args { for i, arg := range args {
// dont reorder any args after a --
// read about -- here:
// https://unix.stackexchange.com/questions/11376/what-does-double-dash-mean-also-known-as-bare-double-dash
if arg == "--" { if arg == "--" {
remainingArgs = append(remainingArgs, args[i:]...) remainingArgs = append(remainingArgs, args[i:]...)
break break
@ -229,21 +233,22 @@ func reorderArgs(commandFlags []Flag, args []string) []string {
if readFlagValue && !strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") { if readFlagValue && !strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") {
readFlagValue = false readFlagValue = false
reorderedFlags = append(reorderedFlags, arg) reorderedArgs = append(reorderedArgs, arg)
continue continue
} }
readFlagValue = false readFlagValue = false
if arg != "-" && strings.HasPrefix(arg, "-") { if arg != "-" && strings.HasPrefix(arg, "-") {
reorderedFlags = append(reorderedFlags, arg) reorderedArgs = append(reorderedArgs, arg)
readFlagValue = !strings.Contains(arg, "=") readFlagValue = !strings.Contains(arg, "=")
} else { continue
remainingArgs = append(remainingArgs, arg)
}
} }
return append(reorderedFlags, remainingArgs...) remainingArgs = append(remainingArgs, arg)
}
return append(reorderedArgs, remainingArgs...)
} }
// Names returns the names including short names and aliases. // Names returns the names including short names and aliases.