]> git.proxmox.com Git - rustc.git/blame - vendor/clap/examples/escaped-positional.md
New upstream version 1.65.0+dfsg1
[rustc.git] / vendor / clap / examples / escaped-positional.md
CommitLineData
f2b60f7d 1**This requires enabling the [`cargo` feature flag][crate::_features].**
04454e1e
FG
2
3You can use `--` to escape further arguments.
4
5Let's see what this looks like in the help:
6```console
7$ escaped-positional --help
8clap [..]
9A simple to use, efficient, and full-featured Command Line Argument Parser
10
11USAGE:
12 escaped-positional[EXE] [OPTIONS] [-- <SLOP>...]
13
14ARGS:
15 <SLOP>...
16
17OPTIONS:
18 -f
19 -h, --help Print help information
20 -p <PEAR>
21 -V, --version Print version information
22
23```
24
25Here is a baseline without any arguments:
26```console
27$ escaped-positional
28-f used: false
29-p's value: None
30'slops' values: []
31
32```
33
34Notice that we can't pass positional arguments before `--`:
35```console
36$ escaped-positional foo bar
37? failed
38error: Found argument 'foo' which wasn't expected, or isn't valid in this context
39
40USAGE:
41 escaped-positional[EXE] [OPTIONS] [-- <SLOP>...]
42
43For more information try --help
44
45```
46
47But you can after:
48```console
49$ escaped-positional -f -p=bob -- sloppy slop slop
50-f used: true
51-p's value: Some("bob")
52'slops' values: ["sloppy", "slop", "slop"]
53
54```
55
56As mentioned, the parser will directly pass everything through:
57```console
58$ escaped-positional -- -f -p=bob sloppy slop slop
59-f used: false
60-p's value: None
61'slops' values: ["-f", "-p=bob", "sloppy", "slop", "slop"]
62
63```