required positional args
This commit is contained in:
parent
8111804d17
commit
58e62faa3d
3
parse.go
3
parse.go
|
@ -356,6 +356,9 @@ func process(specs []*spec, args []string) error {
|
|||
for _, spec := range specs {
|
||||
if spec.positional {
|
||||
if spec.multiple {
|
||||
if spec.required && len(positionals) == 0 {
|
||||
return fmt.Errorf("%s is required", spec.long)
|
||||
}
|
||||
err := setSlice(spec.dest, positionals, true)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error processing %s: %v", spec.long, err)
|
||||
|
|
8
usage.go
8
usage.go
|
@ -54,7 +54,13 @@ func (p *Parser) WriteUsage(w io.Writer) {
|
|||
fmt.Fprint(w, " ")
|
||||
up := strings.ToUpper(spec.long)
|
||||
if spec.multiple {
|
||||
fmt.Fprintf(w, "[%s [%s ...]]", up, up)
|
||||
if !spec.required {
|
||||
fmt.Fprint(w, "[")
|
||||
}
|
||||
fmt.Fprintf(w, "%s [%s ...]", up, up)
|
||||
if !spec.required {
|
||||
fmt.Fprint(w, "]")
|
||||
}
|
||||
} else {
|
||||
fmt.Fprint(w, up)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue