Skip to content

Commit ab3be54

Browse files
committed
Make positional arguments optional
1 parent f5ecdd3 commit ab3be54

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ GNU command line argument rules:
2222
- options may appear in any order
2323
- the argument `--` terminates all options so that all following arguments are treated as non-options
2424
- an argument value of `-` is allowed, usually used to mean standard in or out streams
25+
- options may be specified multiple times, only the last one determines its value
2526

2627
Additional features:
2728

28-
- options may be specified multiple times, only the last one determines its value
29-
- counting options are supported: `-vvv` sets `v = 3`
29+
- counting options: `-vvv` sets `v = 3`
30+
- appending options: `-v 1 -v 2` sets `v = []int{1, 2}`
31+
- boolean options: `--var` enables and `--no-var` disables a boolean
3032
- options can be composite types, such as structs, slices, or maps:
31-
- `-v 1,2,3` sets `v = []int{1,2,3}`
32-
- `-v [1 2 3]` sets `v = []int{1,2,3}`
33+
- `-v 1,2,3` sets `v = []int{1, 2, 3}`
34+
- `-v [1 2 3]` sets `v = []int{1, 2, 3}`
3335
- `-v {1:one 2:two}` sets `map[int]string{1:"one", 2:"two"}`
3436
- `-v {string 42 [0 1]}` sets `struct{S string, I int, B [2]bool}{"string", 42, false, true}`
3537
- options can retrieve their list/dict values from a source (such as SQL):

argp.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -758,15 +758,15 @@ func (argp *Argp) parse(args []string) (*Argp, []string, error) {
758758
v.isSet = true
759759
index++
760760
}
761-
for _, v := range argp.vars {
762-
if v.Index != -1 && index <= v.Index && v.Default == nil {
763-
name := v.Name
764-
if name == "" {
765-
name = strconv.Itoa(index)
766-
}
767-
return argp, nil, fmt.Errorf("argument %v is missing", name)
768-
}
769-
}
761+
//for _, v := range argp.vars {
762+
// if v.Index != -1 && index <= v.Index && v.Default == nil {
763+
// name := v.Name
764+
// if name == "" {
765+
// name = strconv.Itoa(index)
766+
// }
767+
// return argp, nil, fmt.Errorf("argument %v is missing", name)
768+
// }
769+
//}
770770

771771
// rest arguments
772772
v := argp.findRest()

0 commit comments

Comments
 (0)