use shellComplete instead of
ignoreErrors`, clean up
This commit is contained in:
parent
f3295e3cdb
commit
9e7226ec28
10
parse.go
10
parse.go
@ -14,13 +14,13 @@ type iterativeParser interface {
|
|||||||
// 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
|
// transforming any arguments. Otherwise, there is no way we can discriminate
|
||||||
// combined short options from common arguments that should be left untouched.
|
// combined short options from common arguments that should be left untouched.
|
||||||
// Pass `ignoreErrors` to continue parsing options on failure, for example
|
// Pass `shellComplete` to continue parsing options on failure during shell
|
||||||
// during shell completion when the user-supplied options may be incomplete.
|
// completion when, the user-supplied options may be incomplete.
|
||||||
func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, ignoreErrors bool) error {
|
func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, shellComplete bool) error {
|
||||||
for {
|
for {
|
||||||
err := set.Parse(args)
|
err := set.Parse(args)
|
||||||
if !ip.useShortOptionHandling() || err == nil {
|
if !ip.useShortOptionHandling() || err == nil {
|
||||||
if ignoreErrors {
|
if shellComplete {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -28,7 +28,7 @@ func parseIter(set *flag.FlagSet, ip iterativeParser, args []string, ignoreError
|
|||||||
|
|
||||||
errStr := err.Error()
|
errStr := err.Error()
|
||||||
trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: -")
|
trimmed := strings.TrimPrefix(errStr, "flag provided but not defined: -")
|
||||||
if !ignoreErrors && errStr == trimmed {
|
if errStr == trimmed {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user