mirror of
https://github.com/CLIUtils/CLI11.git
synced 2026-01-19 04:52:08 +00:00
Escape transform and docs (#970)
Update some documentation and add a string escape transformer so escaped strings can be handled on the command line as well as in the config files. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
39
README.md
39
README.md
@@ -451,8 +451,8 @@ Before parsing, you can set the following options:
|
||||
This equivalent to calling `->delimiter(delim)` and `->join()`. Valid values
|
||||
are `CLI::MultiOptionPolicy::Throw`, `CLI::MultiOptionPolicy::Throw`,
|
||||
`CLI::MultiOptionPolicy::TakeLast`, `CLI::MultiOptionPolicy::TakeFirst`,
|
||||
`CLI::MultiOptionPolicy::Join`, `CLI::MultiOptionPolicy::TakeAll`, and
|
||||
`CLI::MultiOptionPolicy::Sum` 🆕.
|
||||
`CLI::MultiOptionPolicy::Join`, `CLI::MultiOptionPolicy::TakeAll`,
|
||||
`CLI::MultiOptionPolicy::Sum` 🆕, and `CLI::MultiOptionPolicy::Reverse` 🚧.
|
||||
- `->check(std::string(const std::string &), validator_name="",validator_description="")`:
|
||||
Define a check function. The function should return a non empty string with
|
||||
the error message if the check fails
|
||||
@@ -702,6 +702,17 @@ filters on the key values is performed.
|
||||
`CLI::FileOnDefaultPath(default_path, false)`. This allows multiple paths to
|
||||
be chained using multiple transform calls.
|
||||
|
||||
- `CLI::EscapedString`: 🚧 can be used to process an escaped string. The
|
||||
processing is equivalent to that used for TOML config files, see
|
||||
[TOML strings](https://toml.io/en/v1.0.0#string). With 2 notable exceptions.
|
||||
\` can also be used as a literal string notation, and it also allows binary
|
||||
string notation see
|
||||
[binary strings](https://cliutils.github.io/CLI11/book/chapters/config.html).
|
||||
The escaped string processing will remove outer quotes if present, `"` will
|
||||
indicate a string with potential escape sequences, `'` and \` will indicate a
|
||||
literal string and the quotes removed but no escape sequences will be
|
||||
processed. This is the same escape processing as used in config files.
|
||||
|
||||
##### Validator operations
|
||||
|
||||
Validators are copyable and have a few operations that can be performed on them
|
||||
@@ -873,9 +884,11 @@ through the `add_subcommand` method have the same restrictions as option names.
|
||||
- `--subcommand1.subsub.f val` (short form nested subcommand option)
|
||||
|
||||
The use of dot notation in this form is equivalent `--subcommand.long <args>` =>
|
||||
`subcommand --long <args> ++`. Nested subcommands also work `"sub1.subsub"`
|
||||
would trigger the subsub subcommand in `sub1`. This is equivalent to "sub1
|
||||
subsub"
|
||||
`subcommand --long <args> ++`. Nested subcommands also work `sub1.subsub` would
|
||||
trigger the subsub subcommand in `sub1`. This is equivalent to "sub1 subsub".
|
||||
Quotes around the subcommand names are permitted 🚧 following the TOML standard
|
||||
for such specification. This includes allowing escape sequences. For example
|
||||
`"subcommand".'f'` or `"subcommand.with.dots".arg1 = value`.
|
||||
|
||||
#### Subcommand options
|
||||
|
||||
@@ -1209,19 +1222,22 @@ 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 files, including multi-line strings 🚧, 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:
|
||||
default reader can also accept files in INI format as well. The config reader
|
||||
can read most aspects of TOML files including strings both literal 🚧 and with
|
||||
potential escape sequences 🚧, digit separators 🚧, and multi-line strings 🚧,
|
||||
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:
|
||||
|
||||
```toml
|
||||
# Comments are supported, using a #
|
||||
# The default section is [default], case insensitive
|
||||
|
||||
value = 1
|
||||
value2 = 123_456 # a string with separators
|
||||
str = "A string"
|
||||
str2 = "A string\nwith new lines"
|
||||
str3 = 'A literal "string"'
|
||||
vector = [1,2,3]
|
||||
str_vector = ["one","two","and three"]
|
||||
|
||||
@@ -1229,6 +1245,7 @@ str_vector = ["one","two","and three"]
|
||||
[subcommand]
|
||||
in_subcommand = Wow
|
||||
sub.subcommand = true
|
||||
"sub"."subcommand2" = "string_value"
|
||||
```
|
||||
|
||||
or equivalently in INI format
|
||||
|
||||
Reference in New Issue
Block a user