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