clap/examples/22_stop_parsing_with_--.md
Ed Page bfa02fd418 test: More thoroughly test examples
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"
2021-11-23 13:13:41 -06:00

1.1 KiB

You can use -- to escape further arguments.

Let's see what this looks like in the help:

$ 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:

$ 22_stop_parsing_with_--
-f used: false
-p's value: None
'slops' values: None

Notice that we can't pass positional arguments before --:

$ 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:

$ 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:

$ 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"])