simplify processing of positionals a little
This commit is contained in:
parent
6266d3e5b7
commit
7b1d9ef23f
9
parse.go
9
parse.go
|
@ -383,11 +383,13 @@ func process(specs []*spec, args []string) error {
|
||||||
|
|
||||||
// process positionals
|
// process positionals
|
||||||
for _, spec := range specs {
|
for _, spec := range specs {
|
||||||
if spec.positional {
|
if !spec.positional {
|
||||||
if spec.multiple {
|
continue
|
||||||
|
}
|
||||||
if spec.required && len(positionals) == 0 {
|
if spec.required && len(positionals) == 0 {
|
||||||
return fmt.Errorf("%s is required", spec.long)
|
return fmt.Errorf("%s is required", spec.long)
|
||||||
}
|
}
|
||||||
|
if spec.multiple {
|
||||||
err := setSlice(spec.dest, positionals, true)
|
err := setSlice(spec.dest, positionals, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error processing %s: %v", spec.long, err)
|
return fmt.Errorf("error processing %s: %v", spec.long, err)
|
||||||
|
@ -399,9 +401,6 @@ func process(specs []*spec, args []string) error {
|
||||||
return fmt.Errorf("error processing %s: %v", spec.long, err)
|
return fmt.Errorf("error processing %s: %v", spec.long, err)
|
||||||
}
|
}
|
||||||
positionals = positionals[1:]
|
positionals = positionals[1:]
|
||||||
} else if spec.required {
|
|
||||||
return fmt.Errorf("%s is required", spec.long)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(positionals) > 0 {
|
if len(positionals) > 0 {
|
||||||
|
|
Loading…
Reference in New Issue