You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If this is called with no arguments, it will remove the configuration file option (like `set_help_flag`). Setting a configuration option is special. If it is present, it will be read along with the normal command line arguments. The file will be read if it exists, and does not throw an error unless `required` is `true`. Configuration files are in `ini` format by default, The reader can also accept many files in [TOML] format 🆕. (other formats can be added by an adept user, some variations are available through customization points in the default formatter). An example of a file:
682
+
If this is called with no arguments, it will remove the configuration file option (like `set_help_flag`). Setting a configuration option is special. If it is present, it will be read along with the normal command line arguments. The file will be read if it exists, and does not throw an error unless `required` is `true`. Configuration files are in [TOML] format by default 🚧, though the default reader can also accept files in INI format as well 🆕. It should be noted that CLI11 does not contain a full TOML parser but can read strings from most TOML file and run them through the CLI11 parser. Other formats can be added by an adept user, some variations are available through customization points in the default formatter. An example of a TOML file 🆕:
683
683
684
684
```ini
685
-
; Comments are supported, using a ;
686
-
; The default section is [default], case insensitive
685
+
# Comments are supported, using a #
686
+
# The default section is [default], case insensitive
687
687
688
688
value = 1
689
689
str = "A string"
690
-
vector = 1 2 3
691
-
str_vector = "one""two""and three"
690
+
vector = [1,2,3]
691
+
str_vector = ["one","two","and three"]
692
692
693
-
; Sections map to subcommands
693
+
# Sections map to subcommands
694
694
[subcommand]
695
695
in_subcommand = Wow
696
696
sub.subcommand = true
697
697
```
698
-
or equivalently in TOML 🆕
699
-
```toml
700
-
# Comments are supported, using a #
701
-
# The default section is [default], case insensitive
698
+
or equivalently in INI format
699
+
```ini
700
+
; Comments are supported, using a ;
701
+
; The default section is [default], case insensitive
702
702
703
703
value = 1
704
704
str = "A string"
705
-
vector = [1,2,3]
706
-
str_vector = ["one","two","and three"]
705
+
vector = 1 2 3
706
+
str_vector = "one""two""and three"
707
707
708
-
# Sections map to subcommands
708
+
; Sections map to subcommands
709
709
[subcommand]
710
710
in_subcommand = Wow
711
711
sub.subcommand = true
712
712
```
713
713
714
-
Spaces before and after the name and argument are ignored. Multiple arguments are separated by spaces. One set of quotes will be removed, preserving spaces (the same way the command line works). Boolean options can be `true`, `on`, `1`, `yes`, `enable`; or `false`, `off`, `0`, `no`, `disable` (case insensitive). Sections (and `.` separated names) are treated as subcommands (note: this does not necessarily mean that subcommand was passed, it just sets the "defaults"). You cannot set positional-only arguments. 🆕 Subcommands can be triggered from config files if the `configurable` flag was set on the subcommand. Then use `[subcommand]` notation will trigger a subcommand and cause it to act as if it were on the command line.
714
+
Spaces before and after the name and argument are ignored. Multiple arguments are separated by spaces. One set of quotes will be removed, preserving spaces (the same way the command line works). Boolean options can be `true`, `on`, `1`, `yes`, `enable`; or `false`, `off`, `0`, `no`, `disable` (case insensitive). Sections (and `.` separated names) are treated as subcommands (note: this does not necessarily mean that subcommand was passed, it just sets the "defaults"). You cannot set positional-only arguments. 🆕 Subcommands can be triggered from configuration files if the `configurable` flag was set on the subcommand. Then the use of`[subcommand]` notation will trigger a subcommand and cause it to act as if it were on the command line.
715
715
716
716
To print a configuration file from the passed
717
717
arguments, use `.config_to_str(default_also=false, prefix="", write_description=false)`, where `default_also` will also show any defaulted arguments, `prefix` will add a prefix, and `write_description` will include option descriptions. See [Config files](https://cliutils.github.io/CLI11/book/chapters/config.html) for some additional details.
@@ -744,7 +744,7 @@ The App class was designed allow toolkits to subclass it, to provide preset defa
744
744
but before run behavior, while
745
745
still giving the user freedom to `callback` on the main app.
746
746
747
-
The most important parse function is `parse(std::vector<std::string>)`, which takes a reversed list of arguments (so that `pop_back` processes the args in the correct order). `get_help_ptr` and `get_config_ptr` give you access to the help/config option pointers. The standard `parse` manually sets the name from the first argument, so it should not be in this vector. You can also use `parse(string, bool)` to split up and parse a string; the optional bool should be set to true if you are
747
+
The most important parse function is `parse(std::vector<std::string>)`, which takes a reversed list of arguments (so that `pop_back` processes the args in the correct order). `get_help_ptr` and `get_config_ptr` give you access to the help/config option pointers. The standard `parse` manually sets the name from the first argument, so it should not be in this vector. You can also use `parse(string, bool)` to split up and parse a string; the optional boolean should be set to true if you are
748
748
including the program name in the string, and false otherwise.
749
749
750
750
Also, in a related note, the `App` you get a pointer to is stored in the parent `App` in a `shared_ptr`s (similar to `Option`s) and are deleted when the main `App` goes out of scope unless the object has another owner.
Copy file name to clipboardExpand all lines: book/chapters/config.md
+22-22Lines changed: 22 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,39 +41,39 @@ If it is needed to get the configuration file name used this can be obtained via
41
41
42
42
## Configure file format
43
43
44
-
Here is an example configuration file, in INI format:
44
+
Here is an example configuration file, in [TOML](https://github.com/toml-lang/toml) format:
45
45
46
46
```ini
47
-
; Comments are supported, using a ;
48
-
; The default section is [default], case insensitive
47
+
# Comments are supported, using a #
48
+
# The default section is [default], case insensitive
49
49
50
50
value = 1
51
51
str = "A string"
52
-
vector = 1 2 3
52
+
vector = [1,2,3]
53
53
54
-
; Section map to subcommands
54
+
# Section map to subcommands
55
55
[subcommand]
56
56
in_subcommand = Wow
57
-
sub.subcommand = true
57
+
[subcommand.sub]
58
+
subcommand = true # could also be give as sub.subcommand=true
58
59
```
59
60
60
61
Spaces before and after the name and argument are ignored. Multiple arguments are separated by spaces. One set of quotes will be removed, preserving spaces (the same way the command line works). Boolean options can be `true`, `on`, `1`, `y`, `t`, `+`, `yes`, `enable`; or `false`, `off`, `0`, `no`, `n`, `f`, `-`, `disable`, (case insensitive). Sections (and `.` separated names) are treated as subcommands (note: this does not necessarily mean that subcommand was passed, it just sets the "defaults". If a subcommand is set to `configurable` then passing the subcommand using `[sub]` in a configuration file will trigger the subcommand.)
61
62
62
-
CLI11 also supports configuration file in [TOML](https://github.com/toml-lang/toml) format.
63
+
CLI11 also supports configuration file in INI format.
63
64
64
-
```toml
65
-
# Comments are supported, using a #
66
-
# The default section is [default], case insensitive
65
+
```ini
66
+
; Comments are supported, using a ;
67
+
; The default section is [default], case insensitive
67
68
68
69
value = 1
69
70
str = "A string"
70
-
vector = [1,2,3]
71
+
vector = 1 2 3
71
72
72
-
# Section map to subcommands
73
+
; Section map to subcommands
73
74
[subcommand]
74
75
in_subcommand = Wow
75
-
[subcommand.sub]
76
-
subcommand = true# could also be give as sub.subcommand=true
76
+
sub.subcommand = true
77
77
```
78
78
79
79
The main differences are in vector notation and comment character. Note: CLI11 is not a full TOML parser as it just reads values as strings. It is possible (but not recommended) to mix notation.
@@ -83,16 +83,16 @@ The main differences are in vector notation and comment character. Note: CLI11
83
83
To print a configuration file from the passed arguments, use `.config_to_str(default_also=false, prefix="", write_description=false)`, where `default_also` will also show any defaulted arguments, `prefix` will add a prefix, and `write_description` will include option descriptions.
84
84
85
85
### Customization of configure file output
86
-
The default config parser/generator has some customization points that allow variations on the INI format. The default formatter has a base configuration that matches the INI format. It defines 5 characters that define how different aspects of the configuration are handled
86
+
The default config parser/generator has some customization points that allow variations on the TOML format. The default formatter has a base configuration that matches the TOML format. It defines 5 characters that define how different aspects of the configuration are handled
87
87
```cpp
88
88
/// the character used for comments
89
-
char commentChar = ';';
89
+
char commentChar = '#';
90
90
/// the character used to start an array '\0' is a default to not use
91
-
char arrayStart = '\0';
91
+
char arrayStart = '[';
92
92
/// the character used to end an array '\0' is a default to not use
93
-
char arrayEnd = '\0';
93
+
char arrayEnd = ']';
94
94
/// the character used to separate elements in an array
95
-
char arraySeparator = '';
95
+
char arraySeparator = ',';
96
96
/// the character used separate the name from the value
97
97
char valueDelimiter = '=';
98
98
```
@@ -111,11 +111,11 @@ auto config_base=app.get_config_formatter_base();
111
111
config_base->valueSeparator(':');
112
112
```
113
113
114
-
The default configuration file will read TOML files, but will write out files in the INI format. To specify outputting TOML formatted files use
114
+
The default configuration file will read INI files, but will write out files in the TOML format. To specify outputting INI formatted files use
0 commit comments