Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

correct match parsed flag when it has same shortname with subcommand #87

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"strconv"
"strings"

"text/template"
)

Expand Down Expand Up @@ -94,7 +93,8 @@ func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []stri

// if the final argument (--) is seen, then we stop checking because all
// further values are trailing arguments.
if determineArgType(a) == argIsFinal {
argType := determineArgType(a)
if argType == argIsFinal {
return argsNotUsed
}

Expand Down Expand Up @@ -122,10 +122,10 @@ func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []stri

// search all args for a corresponding parsed value
for _, pv := range parsedValues {
// this argumenet was a key
// this argument was a key
// debugPrint(pv.Key, "==", arg)
debugPrint(pv.Key + "==" + arg + " || (" + strconv.FormatBool(pv.IsPositional) + " && " + pv.Value + " == " + arg + ")")
if pv.Key == arg || (pv.IsPositional && pv.Value == arg) {
if pv.Key == arg || (argType == argIsPositional && pv.IsPositional && pv.Value == arg) {
debugPrint("Found matching parsed arg for " + pv.Key)
foundArgUsed = true // the arg was used in this parsedValues set
// if the value is not a positional value and the parsed value had a
Expand All @@ -145,7 +145,7 @@ func findArgsNotInParsedValues(args []string, parsedValues []parsedValue) []stri
// if the arg was not used in any parsed values, then we add it to the slice
// of arguments not used
if !foundArgUsed {
argsNotUsed = append(argsNotUsed, arg)
argsNotUsed = append(argsNotUsed, a)
}
}

Expand Down
2 changes: 1 addition & 1 deletion subCommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func (sc *Subcommand) parseAllFlagsFromArgs(p *Parser, args []string) ([]string,

// if the next arg was not found, then show a Help message
if !nextArgExists {
p.ShowHelpWithMessage("Expected a following arg for flag " + a + ", but it did not exist.")
p.ShowHelpWithMessage("Expected a following arg for flag " + args[i] + ", but it did not exist.")
exitOrPanic(2)
}
valueSet, err := setValueForParsers(a, nextArg, p, sc)
Expand Down