update vars and args
This commit is contained in:
parent
0f9d8a9abd
commit
406a1c31b0
20
command.go
20
command.go
@ -190,7 +190,7 @@ func (c *Command) parseFlags(args Args) (*flag.FlagSet, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !c.SkipArgReorder {
|
if !c.SkipArgReorder {
|
||||||
args = reorderArgs(args)
|
args = reorderArgs(c.Flags, args)
|
||||||
}
|
}
|
||||||
|
|
||||||
set, err := parseIter(c, args)
|
set, err := parseIter(c, args)
|
||||||
@ -214,34 +214,36 @@ func (c *Command) useShortOptionHandling() bool {
|
|||||||
return c.UseShortOptionHandling
|
return c.UseShortOptionHandling
|
||||||
}
|
}
|
||||||
|
|
||||||
// reorderArgs moves all flags before arguments as this is what flag expects
|
// reorderArgs moves all flags (reorderedFlags) before arguments (remainingArgs)
|
||||||
func reorderArgs(args []string) []string {
|
// as this is what flag expects.
|
||||||
var nonflags, flags []string
|
func reorderArgs(commandFlags []Flag, args []string) []string {
|
||||||
|
var remainingArgs []string
|
||||||
|
var reorderedFlags []string
|
||||||
|
|
||||||
readFlagValue := false
|
readFlagValue := false
|
||||||
for i, arg := range args {
|
for i, arg := range args {
|
||||||
if arg == "--" {
|
if arg == "--" {
|
||||||
nonflags = append(nonflags, args[i:]...)
|
remainingArgs = append(remainingArgs, args[i:]...)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if readFlagValue && !strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") {
|
if readFlagValue && !strings.HasPrefix(arg, "-") && !strings.HasPrefix(arg, "--") {
|
||||||
readFlagValue = false
|
readFlagValue = false
|
||||||
flags = append(flags, arg)
|
reorderedFlags = append(reorderedFlags, arg)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
readFlagValue = false
|
readFlagValue = false
|
||||||
|
|
||||||
if arg != "-" && strings.HasPrefix(arg, "-") {
|
if arg != "-" && strings.HasPrefix(arg, "-") {
|
||||||
flags = append(flags, arg)
|
reorderedFlags = append(reorderedFlags, arg)
|
||||||
|
|
||||||
readFlagValue = !strings.Contains(arg, "=")
|
readFlagValue = !strings.Contains(arg, "=")
|
||||||
} else {
|
} else {
|
||||||
nonflags = append(nonflags, arg)
|
remainingArgs = append(remainingArgs, arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return append(flags, nonflags...)
|
return append(reorderedFlags, remainingArgs...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Names returns the names including short names and aliases.
|
// Names returns the names including short names and aliases.
|
||||||
|
Loading…
Reference in New Issue
Block a user