mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
bfa02fd418
This ports our example testing over to [trycmd](https://docs.rs/) so we can: - More thoroughly test our examples - Provide always-up-to-date example usage The old way of testing automatically picked up examples. This new way requires we have a `.md` file that uses the example in some way. Notes: - Moved overall example description to the `.md` file - I added cross-linking between related examples - `14_groups` had a redundant paragraph (twice talked about "one and only one"
54 lines
1.1 KiB
Markdown
54 lines
1.1 KiB
Markdown
You can use `--` to escape further arguments.
|
|
|
|
Let's see what this looks like in the help:
|
|
```bash
|
|
$ 22_stop_parsing_with_-- --help
|
|
myprog
|
|
|
|
USAGE:
|
|
22_stop_parsing_with_--[EXE] [OPTIONS] [-- <slop>...]
|
|
|
|
ARGS:
|
|
<slop>...
|
|
|
|
OPTIONS:
|
|
-f
|
|
-h, --help Print help information
|
|
-p <pea>
|
|
```
|
|
|
|
Here is a baseline without any arguments:
|
|
```bash
|
|
$ 22_stop_parsing_with_--
|
|
-f used: false
|
|
-p's value: None
|
|
'slops' values: None
|
|
```
|
|
|
|
Notice that we can't pass positional arguments before `--`:
|
|
```bash
|
|
$ 22_stop_parsing_with_-- foo bar
|
|
? failed
|
|
error: Found argument 'foo' which wasn't expected, or isn't valid in this context
|
|
|
|
USAGE:
|
|
22_stop_parsing_with_--[EXE] [OPTIONS] [-- <slop>...]
|
|
|
|
For more information try --help
|
|
```
|
|
|
|
But you can after:
|
|
```bash
|
|
$ 22_stop_parsing_with_-- -f -p=bob -- sloppy slop slop
|
|
-f used: true
|
|
-p's value: Some("bob")
|
|
'slops' values: Some(["sloppy", "slop", "slop"])
|
|
```
|
|
|
|
As mentioned, the parser will directly pass everything through:
|
|
```bash
|
|
$ 22_stop_parsing_with_-- -- -f -p=bob sloppy slop slop
|
|
-f used: false
|
|
-p's value: None
|
|
'slops' values: Some(["-f", "-p=bob", "sloppy", "slop", "slop"])
|
|
```
|