2022-07-19 18:29:31 +00:00
|
|
|
**This requires enabling the [`cargo` feature flag][crate::_features].**
|
2021-12-08 22:46:49 +00:00
|
|
|
|
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 --help
|
2021-11-30 18:30:19 +00:00
|
|
|
A simple to use, efficient, and full-featured Command Line Argument Parser
|
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Usage:
|
2021-12-15 17:12:16 +00:00
|
|
|
escaped-positional[EXE] [OPTIONS] [-- <SLOP>...]
|
2021-11-30 18:30:19 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Arguments:
|
2022-08-29 20:09:06 +00:00
|
|
|
[SLOP]...
|
2021-11-30 18:30:19 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2021-11-30 18:30:19 +00:00
|
|
|
-f
|
|
|
|
-p <PEAR>
|
2022-07-22 20:43:49 +00:00
|
|
|
-h, --help Print help information
|
2021-11-30 18:30:19 +00:00
|
|
|
-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
|
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 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
|
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Usage:
|
2021-12-15 17:12:16 +00:00
|
|
|
escaped-positional[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 -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 -- -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
|
|
|
```
|