add argIsFlag check

This commit is contained in:
Lynn Cyrin 2019-09-11 19:25:51 -07:00
parent bfeb4c88ec
commit 7d0751fa13
No known key found for this signature in database
GPG Key ID: EE9CCB427DFEC897

View File

@ -238,7 +238,7 @@ func reorderArgs(commandFlags []Flag, args []string) []string {
}
readFlagValue = false
if arg != "-" && strings.HasPrefix(arg, "-") {
if arg != "-" && strings.HasPrefix(arg, "-") && argIsFlag(commandFlags, arg) {
reorderedArgs = append(reorderedArgs, arg)
readFlagValue = !strings.Contains(arg, "=")
@ -251,6 +251,18 @@ func reorderArgs(commandFlags []Flag, args []string) []string {
return append(reorderedArgs, remainingArgs...)
}
func argIsFlag(commandFlags []Flag, arg string) bool {
strippedArg := strings.ReplaceAll(arg, "-", "")
for _, flag := range commandFlags {
for _, key := range strings.Split(flag.GetName(), ",") {
if key == strippedArg {
return true
}
}
}
return false
}
// Names returns the names including short names and aliases.
func (c Command) Names() []string {
names := []string{c.Name}