diff options
| author | Mario Hros <[email protected]> | 2017-03-30 20:32:39 +0200 |
|---|---|---|
| committer | Mario Hros <[email protected]> | 2017-03-30 20:32:39 +0200 |
| commit | 58e62faa3d380dc61dc3be3ce78672081779c0fc (patch) | |
| tree | 65f1eb7fd4a0be1be79561ae98fa6d25915fd0b2 | |
| parent | 8111804d1774e2f9e2f7f734a15d2fb9ca684685 (diff) | |
required positional args
| -rw-r--r-- | parse.go | 3 | ||||
| -rw-r--r-- | usage.go | 8 |
2 files changed, 10 insertions, 1 deletions
@@ -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) @@ -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) } |
