From 7d0751fa1309a01b405cde327cc43275d13016a2 Mon Sep 17 00:00:00 2001 From: Lynn Cyrin Date: Wed, 11 Sep 2019 19:25:51 -0700 Subject: [PATCH] add argIsFlag check --- command.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/command.go b/command.go index d33435e..6471f10 100644 --- a/command.go +++ b/command.go @@ -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}