Skip to content

Commit a1acafd

Browse files
committed
update book and readme
1 parent 137e2e4 commit a1acafd

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,8 @@ app.set_config("--config")->expected(1, X);
781781
782782
Where X is some positive number and will allow up to `X` configuration files to be specified by separate `--config` arguments. Value strings with quote characters in it will be printed with a single quote. All other arguments will use double quote. Empty strings will use a double quoted argument. Numerical or boolean values are not quoted.
783783
784+
For options or flags which allow 0 arguments to be passed specifing an empty string in the config file, `{}`, or `[]` will convert the result to the default value specified via `default_str` or `default_val` on the option 🚧. If no user specified default is given the result is an empty string or the converted value of an empty string.
785+
784786
### Inheriting defaults
785787
786788
Many of the defaults for subcommands and even options are inherited from their creators. The inherited default values for subcommands are `allow_extras`, `prefix_command`, `ignore_case`, `ignore_underscore`, `fallthrough`, `group`, `footer`,`immediate_callback` and maximum number of required subcommands. The help flag existence, name, and description are inherited, as well.

book/chapters/options.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,40 @@ Vectors will be replaced by the parsed content if the option is given on the com
7272

7373
A definition of a container for purposes of CLI11 is a type with a `end()`, `insert(...)`, `clear()` and `value_type` definitions. This includes `vector`, `set`, `deque`, `list`, `forward_iist`, `map`, `unordered_map` and a few others from the standard library, and many other containers from the boost library.
7474

75+
76+
77+
### Empty containers
78+
79+
By default a container will never return an empty container. If it is desired to allow an empty container to be returned, then the option must be modified with a 0 as the minimum expected value
80+
81+
```cpp
82+
std::vector<int> int_vec;
83+
app.add_option("--vec", int_vec, "Empty vector allowed")->expected(0,-1);
84+
```
85+
86+
An empty vector can than be specified on the command line as `--vec {}`
87+
88+
To allow an empty vector from config file, the default must be set in addition to the above modification.
89+
90+
```cpp
91+
std::vector<int> int_vec;
92+
app.add_option("--vec", int_vec, "Empty vector allowed")->expected(0,-1)->default_str("{}");
93+
```
94+
95+
Then in the file
96+
97+
```toml
98+
vec={}
99+
```
100+
101+
or
102+
103+
```toml
104+
vec=[]
105+
```
106+
107+
will generate an empty vector in `int_vec`.
108+
75109
### Containers of containers
76110

77111
Containers of containers are also supported.

0 commit comments

Comments
 (0)