]>
Commit | Line | Data |
---|---|---|
f2b60f7d | 1 | **This requires enabling the [`cargo` feature flag][crate::_features].** |
04454e1e FG |
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 | clap [..] | |
9 | A simple to use, efficient, and full-featured Command Line Argument Parser | |
10 | ||
11 | USAGE: | |
12 | escaped-positional[EXE] [OPTIONS] [-- <SLOP>...] | |
13 | ||
14 | ARGS: | |
15 | <SLOP>... | |
16 | ||
17 | OPTIONS: | |
18 | -f | |
19 | -h, --help Print help information | |
20 | -p <PEAR> | |
21 | -V, --version Print version information | |
22 | ||
23 | ``` | |
24 | ||
25 | Here 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 | ||
34 | Notice that we can't pass positional arguments before `--`: | |
35 | ```console | |
36 | $ escaped-positional foo bar | |
37 | ? failed | |
38 | error: Found argument 'foo' which wasn't expected, or isn't valid in this context | |
39 | ||
40 | USAGE: | |
41 | escaped-positional[EXE] [OPTIONS] [-- <SLOP>...] | |
42 | ||
43 | For more information try --help | |
44 | ||
45 | ``` | |
46 | ||
47 | But 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 | ||
56 | As 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 | ``` |