Skip to content

Commit f7433ec

Browse files
New way of parsing multiple values
1 parent 70ad448 commit f7433ec

File tree

11 files changed

+406
-315
lines changed

11 files changed

+406
-315
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
* `./prog -b -sabc`
9595
* `./prog -bsabc`
9696
* `./prog -bs=abc`
97+
* Fixes for parsing of multiple values. Only these formats are supported:
98+
* `./prog --arg value1 value2 value3`
99+
* `./prog --arg=value1,value2,value3`
97100
* Removed support for delegate in `Config.errorHandler`, `Description`, `ShortDescription`, `Usage` and `Epilog` because of compiler's `closures are not yet supported in CTFE`.
98101

99102
### Other changes

docs/code_snippets/config_arraySep.d renamed to docs/code_snippets/config_valueSep.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ struct T
66
}
77

88
T t1;
9-
assert(CLI!T.parseArgs(t1, ["-a","1:2:3","-a","4","5"]));
9+
assert(CLI!T.parseArgs(t1, ["-a=1:2:3","-a","4","5"]));
1010
assert(t1 == T(["1:2:3","4","5"]));
1111

1212
enum Config cfg = { valueSep: ':' };
1313

1414
T t2;
15-
assert(CLI!(cfg, T).parseArgs(t2, ["-a","1:2:3","-a","4","5"]));
15+
assert(CLI!(cfg, T).parseArgs(t2, ["-a=1:2:3","-a","4","5"]));
1616
assert(t2 == T(["1","2","3","4","5"]));

docs/code_snippets/types_array_comma.d

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ struct T
55
int[] a;
66
}
77

8-
enum Config cfg = { valueSep: ',' };
9-
108
T t;
11-
assert(CLI!(cfg, T).parseArgs(t, ["-a=1,2,3","-a","4,5"]));
9+
assert(CLI!T.parseArgs(t, ["-a=1,2,3","-a","4","5"]));
1210
assert(t == T([1,2,3,4,5]));

docs/code_snippets/types_assoc_array_comma.d

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ struct T
55
int[string] a;
66
}
77

8-
enum Config cfg = { valueSep: ',' };
9-
108
T t;
11-
assert(CLI!(cfg, T).parseArgs(t, ["-a=foo=3,boo=7","-a","bar=4,baz=9"]));
9+
assert(CLI!T.parseArgs(t, ["-a=foo=3,boo=7","-a","bar=4","baz=9"]));
1210
assert(t == T(["foo":3,"boo":7,"bar":4,"baz":9]));

docs/topics/Arity.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
# Arity
22

3-
Sometimes an argument might accept more than one value. This is especially a case when a data member is an array.
3+
Sometimes an argument might accept more than one value. This is especially a case when a data member is an array or associative array.
4+
In this case `argparse` supports two ways of specifying multiple values for an argument:
5+
- `--arg value1 value2 ...`
6+
- `--arg=value1,value2,...`
7+
> Note that `=` is a value of [`Config.assignChar`](Config.md#assignChar) and `,` is a value of [`Config.valueSep`](Config.md#valueSep)
8+
>
9+
{style="note"}
410

5-
`argparse` supports these use cases:
11+
12+
`argparse` supports these use cases for arity:
613
- Exact number of values.
714
- Limited range of minimum-maximum number of values.
815
- Unlimited range where only minimum number of values is provided (e.g. argument accepts _any number_ of values).

docs/topics/reference/Config.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
## Assign character {id="assignChar"}
77

8-
`Config.assignChar` is an assignment character used in arguments with value: `-a=5`, `-b=foo`.
8+
`Config.assignChar` is an assignment character used in arguments with value: `-a=5`, `-boo=foo`.
99

1010
Default is equal sign `=`.
1111

@@ -15,16 +15,13 @@ Example:
1515

1616
## Value separator {id="valueSep"}
1717

18-
When `Config.valueSep` is set to `char.init`, values to array and associative-array receivers are treated as an individual
19-
value. That is, only one argument is appended/inserted per appearance of the argument. If `valueSep` is set to something
20-
else, then each value is first split by the separator, and the individual pieces are treated as values to the same
21-
argument.
18+
`Config.valueSep` is a separator that is used to extract argument values: `-a=5,6,7`, `--boo=foo,far,zoo`.
2219

23-
Default is `char.init`.
20+
Default is `,`.
2421

2522
Example:
2623

27-
<code-block src="code_snippets/config_arraySep.d" lang="c++"/>
24+
<code-block src="code_snippets/config_valueSep.d" lang="c++"/>
2825

2926
## Named argument prefix {id="namedArgPrefix"}
3027

0 commit comments

Comments
 (0)