2021-12-15 17:12:16 +00:00
|
|
|
*Jump to [source](escaped-positional-derive.rs)*
|
2021-11-30 18:30:19 +00:00
|
|
|
|
2021-12-08 22:46:49 +00:00
|
|
|
**This requires enabling the `derive` feature flag.**
|
|
|
|
|
2021-11-30 18:30:19 +00:00
|
|
|
You can use `--` to escape further arguments.
|
|
|
|
|
|
|
|
Let's see what this looks like in the help:
|
2022-01-05 16:54:33 +00:00
|
|
|
```console
|
2021-12-15 17:12:16 +00:00
|
|
|
$ escaped-positional-derive --help
|
2021-11-30 18:30:19 +00:00
|
|
|
clap [..]
|
|
|
|
A simple to use, efficient, and full-featured Command Line Argument Parser
|
|
|
|
|
|
|
|
USAGE:
|
2021-12-15 17:12:16 +00:00
|
|
|
escaped-positional-derive[EXE] [OPTIONS] [-- <SLOP>...]
|
2021-11-30 18:30:19 +00:00
|
|
|
|
|
|
|
ARGS:
|
|
|
|
<SLOP>...
|
|
|
|
|
|
|
|
OPTIONS:
|
|
|
|
-f
|
|
|
|
-h, --help Print help information
|
|
|
|
-p <PEAR>
|
|
|
|
-V, --version Print version information
|
2022-01-05 16:54:33 +00:00
|
|
|
|
2021-11-30 18:30:19 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Here is a baseline without any arguments:
|
2022-01-05 16:54:33 +00:00
|
|
|
```console
|
2021-12-15 17:12:16 +00:00
|
|
|
$ escaped-positional-derive
|
2021-11-30 18:30:19 +00:00
|
|
|
-f used: false
|
|
|
|
-p's value: None
|
|
|
|
'slops' values: []
|
2022-01-05 16:54:33 +00:00
|
|
|
|
2021-11-30 18:30:19 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Notice that we can't pass positional arguments before `--`:
|
2022-01-05 16:54:33 +00:00
|
|
|
```console
|
2021-12-15 17:12:16 +00:00
|
|
|
$ escaped-positional-derive foo bar
|
2021-11-30 18:30:19 +00:00
|
|
|
? failed
|
|
|
|
error: Found argument 'foo' which wasn't expected, or isn't valid in this context
|
|
|
|
|
|
|
|
USAGE:
|
2021-12-15 17:12:16 +00:00
|
|
|
escaped-positional-derive[EXE] [OPTIONS] [-- <SLOP>...]
|
2021-11-30 18:30:19 +00:00
|
|
|
|
|
|
|
For more information try --help
|
2022-01-05 16:54:33 +00:00
|
|
|
|
2021-11-30 18:30:19 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
But you can after:
|
2022-01-05 16:54:33 +00:00
|
|
|
```console
|
2021-12-15 17:12:16 +00:00
|
|
|
$ escaped-positional-derive -f -p=bob -- sloppy slop slop
|
2021-11-30 18:30:19 +00:00
|
|
|
-f used: true
|
|
|
|
-p's value: Some("bob")
|
|
|
|
'slops' values: ["sloppy", "slop", "slop"]
|
2022-01-05 16:54:33 +00:00
|
|
|
|
2021-11-30 18:30:19 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
As mentioned, the parser will directly pass everything through:
|
2022-01-05 16:54:33 +00:00
|
|
|
```console
|
2021-12-15 17:12:16 +00:00
|
|
|
$ escaped-positional-derive -- -f -p=bob sloppy slop slop
|
2021-11-30 18:30:19 +00:00
|
|
|
-f used: false
|
|
|
|
-p's value: None
|
|
|
|
'slops' values: ["-f", "-p=bob", "sloppy", "slop", "slop"]
|
2022-01-05 16:54:33 +00:00
|
|
|
|
2021-11-30 18:30:19 +00:00
|
|
|
```
|