vendor: github.com/urfave/cli v1.22.9
The regression in v1.22.2 has been resolved, so we can drop the replace rule and use the latest v1.22.x version. full diff: https://github.com/urfave/cli/compare/v1.22.1...v1.22.9 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
54
vendor/github.com/urfave/cli/parse.go
generated
vendored
54
vendor/github.com/urfave/cli/parse.go
generated
vendored
@@ -11,45 +11,59 @@ type iterativeParser interface {
|
||||
}
|
||||
|
||||
// To enable short-option handling (e.g., "-it" vs "-i -t") we have to
|
||||
// iteratively catch parsing errors. This way we achieve LR parsing without
|
||||
// iteratively catch parsing errors. This way we achieve LR parsing without
|
||||
// transforming any arguments. Otherwise, there is no way we can discriminate
|
||||
// combined short options from common arguments that should be left untouched.
|
||||
func parseIter(ip iterativeParser, args []string) (*flag.FlagSet, error) {
|
||||
// Pass `shellComplete` to continue parsing options on failure during shell
|
||||
// completion when, the user-supplied options may be incomplete.
|
||||
func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, shellComplete bool) error {
|
||||
for {
|
||||
set, err := ip.newFlagSet()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = set.Parse(args)
|
||||
err := set.Parse(args)
|
||||
if !ip.useShortOptionHandling() || err == nil {
|
||||
return set, err
|
||||
if shellComplete {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
errStr := err.Error()
|
||||
trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: ")
|
||||
trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: -")
|
||||
if errStr == trimmed {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
// regenerate the initial args with the split short opts
|
||||
newArgs := []string{}
|
||||
argsWereSplit := false
|
||||
for i, arg := range args {
|
||||
if arg != trimmed {
|
||||
newArgs = append(newArgs, arg)
|
||||
// skip args that are not part of the error message
|
||||
if name := strings.TrimLeft(arg, "-"); name != trimmed {
|
||||
continue
|
||||
}
|
||||
|
||||
shortOpts := splitShortOptions(set, trimmed)
|
||||
// if we can't split, the error was accurate
|
||||
shortOpts := splitShortOptions(set, arg)
|
||||
if len(shortOpts) == 1 {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
// add each short option and all remaining arguments
|
||||
newArgs = append(newArgs, shortOpts...)
|
||||
newArgs = append(newArgs, args[i+1:]...)
|
||||
args = newArgs
|
||||
// swap current argument with the split version
|
||||
args = append(args[:i], append(shortOpts, args[i+1:]...)...)
|
||||
argsWereSplit = true
|
||||
break
|
||||
}
|
||||
|
||||
// This should be an impossible to reach code path, but in case the arg
|
||||
// splitting failed to happen, this will prevent infinite loops
|
||||
if !argsWereSplit {
|
||||
return err
|
||||
}
|
||||
|
||||
// Since custom parsing failed, replace the flag set before retrying
|
||||
newSet, err := ip.newFlagSet()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*set = *newSet
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user