Merge pull request #3261 from epage/fix-borked-formatting

docs: Fix messed up highlighting
This commit is contained in:
Ed Page 2022-01-05 12:13:46 -06:00 committed by GitHub
commit 2074c56d0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 230 additions and 67 deletions

View file

@ -138,7 +138,7 @@ criterion = "0.3.2"
trybuild = "1.0.18" trybuild = "1.0.18"
rustversion = "1" rustversion = "1"
# Cutting out `filesystem` feature # Cutting out `filesystem` feature
trycmd = { version = "0.8.3", default-features = false, features = ["color-auto", "diff", "examples"] } trycmd = { version = "0.9", default-features = false, features = ["color-auto", "diff", "examples"] }
[[example]] [[example]]
name = "demo" name = "demo"

View file

@ -6,7 +6,7 @@ The crate [`clap-cargo`](https://github.com/crate-ci/clap-cargo) can help in
mimicking cargo's interface. mimicking cargo's interface.
The help looks like: The help looks like:
```bash ```console
$ cargo-example-derive --help $ cargo-example-derive --help
cargo cargo
@ -19,6 +19,7 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
example-derive A simple to use, efficient, and full-featured Command Line Argument Parser example-derive A simple to use, efficient, and full-featured Command Line Argument Parser
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
$ cargo-example-derive example-derive --help $ cargo-example-derive example-derive --help
cargo-example-derive [..] cargo-example-derive [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -30,12 +31,15 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
--manifest-path <MANIFEST_PATH> --manifest-path <MANIFEST_PATH>
-V, --version Print version information -V, --version Print version information
``` ```
Then to directly invoke the command, run: Then to directly invoke the command, run:
```bash ```console
$ cargo-example-derive example-derive $ cargo-example-derive example-derive
None None
$ cargo-example-derive example-derive --manifest-path Cargo.toml $ cargo-example-derive example-derive --manifest-path Cargo.toml
Some("Cargo.toml") Some("Cargo.toml")
``` ```

View file

@ -6,7 +6,7 @@ The crate [`clap-cargo`](https://github.com/crate-ci/clap-cargo) can help in
mimicking cargo's interface. mimicking cargo's interface.
The help looks like: The help looks like:
```bash ```console
$ cargo-example --help $ cargo-example --help
cargo cargo
@ -19,6 +19,7 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
example A simple to use, efficient, and full-featured Command Line Argument Parser example A simple to use, efficient, and full-featured Command Line Argument Parser
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
$ cargo-example example --help $ cargo-example example --help
cargo-example [..] cargo-example [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -30,12 +31,15 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
--manifest-path <PATH> --manifest-path <PATH>
-V, --version Print version information -V, --version Print version information
``` ```
Then to directly invoke the command, run: Then to directly invoke the command, run:
```bash ```console
$ cargo-example example $ cargo-example example
None None
$ cargo-example example --manifest-path Cargo.toml $ cargo-example example --manifest-path Cargo.toml
Some("Cargo.toml") Some("Cargo.toml")
``` ```

View file

@ -3,7 +3,7 @@
**This requires enabling the `derive` feature flag.** **This requires enabling the `derive` feature flag.**
Used to validate README.md's content Used to validate README.md's content
```bash ```console
$ demo --help $ demo --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -16,4 +16,5 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-n, --name <NAME> Name of the person to greet -n, --name <NAME> Name of the person to greet
-V, --version Print version information -V, --version Print version information
``` ```

View file

@ -2,7 +2,7 @@
Example of overriding the magic `bool` behavior Example of overriding the magic `bool` behavior
```bash ```console
$ custom-bool --help $ custom-bool --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -18,6 +18,7 @@ OPTIONS:
--foo <FOO> --foo <FOO>
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ custom-bool $ custom-bool
? failed ? failed
error: The following required arguments were not provided: error: The following required arguments were not provided:
@ -28,16 +29,19 @@ USAGE:
custom-bool[EXE] [OPTIONS] --foo <FOO> <BOOM> custom-bool[EXE] [OPTIONS] --foo <FOO> <BOOM>
For more information try --help For more information try --help
$ custom-bool --foo true false $ custom-bool --foo true false
[examples/derive_ref/custom-bool.rs:31] opt = Opt { [examples/derive_ref/custom-bool.rs:31] opt = Opt {
foo: true, foo: true,
bar: false, bar: false,
boom: false, boom: false,
} }
$ custom-bool --foo true --bar true false $ custom-bool --foo true --bar true false
[examples/derive_ref/custom-bool.rs:31] opt = Opt { [examples/derive_ref/custom-bool.rs:31] opt = Opt {
foo: true, foo: true,
bar: true, bar: true,
boom: false, boom: false,
} }
``` ```

View file

@ -5,7 +5,7 @@
You can use `--` to escape further arguments. You can use `--` to escape further arguments.
Let's see what this looks like in the help: Let's see what this looks like in the help:
```bash ```console
$ escaped-positional-derive --help $ escaped-positional-derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -21,18 +21,20 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-p <PEAR> -p <PEAR>
-V, --version Print version information -V, --version Print version information
``` ```
Here is a baseline without any arguments: Here is a baseline without any arguments:
```bash ```console
$ escaped-positional-derive $ escaped-positional-derive
-f used: false -f used: false
-p's value: None -p's value: None
'slops' values: [] 'slops' values: []
``` ```
Notice that we can't pass positional arguments before `--`: Notice that we can't pass positional arguments before `--`:
```bash ```console
$ escaped-positional-derive foo bar $ escaped-positional-derive foo bar
? failed ? failed
error: Found argument 'foo' which wasn't expected, or isn't valid in this context error: Found argument 'foo' which wasn't expected, or isn't valid in this context
@ -41,20 +43,23 @@ USAGE:
escaped-positional-derive[EXE] [OPTIONS] [-- <SLOP>...] escaped-positional-derive[EXE] [OPTIONS] [-- <SLOP>...]
For more information try --help For more information try --help
``` ```
But you can after: But you can after:
```bash ```console
$ escaped-positional-derive -f -p=bob -- sloppy slop slop $ escaped-positional-derive -f -p=bob -- sloppy slop slop
-f used: true -f used: true
-p's value: Some("bob") -p's value: Some("bob")
'slops' values: ["sloppy", "slop", "slop"] 'slops' values: ["sloppy", "slop", "slop"]
``` ```
As mentioned, the parser will directly pass everything through: As mentioned, the parser will directly pass everything through:
```bash ```console
$ escaped-positional-derive -- -f -p=bob sloppy slop slop $ escaped-positional-derive -- -f -p=bob sloppy slop slop
-f used: false -f used: false
-p's value: None -p's value: None
'slops' values: ["-f", "-p=bob", "sloppy", "slop", "slop"] 'slops' values: ["-f", "-p=bob", "sloppy", "slop", "slop"]
``` ```

View file

@ -5,7 +5,7 @@
You can use `--` to escape further arguments. You can use `--` to escape further arguments.
Let's see what this looks like in the help: Let's see what this looks like in the help:
```bash ```console
$ escaped-positional --help $ escaped-positional --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -21,18 +21,20 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-p <PEAR> -p <PEAR>
-V, --version Print version information -V, --version Print version information
``` ```
Here is a baseline without any arguments: Here is a baseline without any arguments:
```bash ```console
$ escaped-positional $ escaped-positional
-f used: false -f used: false
-p's value: None -p's value: None
'slops' values: [] 'slops' values: []
``` ```
Notice that we can't pass positional arguments before `--`: Notice that we can't pass positional arguments before `--`:
```bash ```console
$ escaped-positional foo bar $ escaped-positional foo bar
? failed ? failed
error: Found argument 'foo' which wasn't expected, or isn't valid in this context error: Found argument 'foo' which wasn't expected, or isn't valid in this context
@ -41,20 +43,23 @@ USAGE:
escaped-positional[EXE] [OPTIONS] [-- <SLOP>...] escaped-positional[EXE] [OPTIONS] [-- <SLOP>...]
For more information try --help For more information try --help
``` ```
But you can after: But you can after:
```bash ```console
$ escaped-positional -f -p=bob -- sloppy slop slop $ escaped-positional -f -p=bob -- sloppy slop slop
-f used: true -f used: true
-p's value: Some("bob") -p's value: Some("bob")
'slops' values: ["sloppy", "slop", "slop"] 'slops' values: ["sloppy", "slop", "slop"]
``` ```
As mentioned, the parser will directly pass everything through: As mentioned, the parser will directly pass everything through:
```bash ```console
$ escaped-positional -- -f -p=bob sloppy slop slop $ escaped-positional -- -f -p=bob sloppy slop slop
-f used: false -f used: false
-p's value: None -p's value: None
'slops' values: ["-f", "-p=bob", "sloppy", "slop", "slop"] 'slops' values: ["-f", "-p=bob", "sloppy", "slop", "slop"]
``` ```

View file

@ -5,7 +5,7 @@
Git is an example of several common subcommand patterns. Git is an example of several common subcommand patterns.
Help: Help:
```bash ```console
$ git-derive $ git-derive
? failed ? failed
git git
@ -22,6 +22,7 @@ SUBCOMMANDS:
clone Clones repos clone Clones repos
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
push pushes things push pushes things
$ git-derive help $ git-derive help
git git
A fictional versioning CLI A fictional versioning CLI
@ -37,6 +38,7 @@ SUBCOMMANDS:
clone Clones repos clone Clones repos
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
push pushes things push pushes things
$ git-derive help add $ git-derive help add
git-derive[EXE]-add git-derive[EXE]-add
adds things adds things
@ -49,10 +51,11 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
``` ```
A basic argument: A basic argument:
```bash ```console
$ git-derive add $ git-derive add
? failed ? failed
git-derive[EXE]-add git-derive[EXE]-add
@ -66,12 +69,15 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
$ git-derive add Cargo.toml Cargo.lock $ git-derive add Cargo.toml Cargo.lock
Adding ["Cargo.toml", "Cargo.lock"] Adding ["Cargo.toml", "Cargo.lock"]
``` ```
External subcommands: External subcommands:
```bash ```console
$ git-derive custom-tool arg1 --foo bar $ git-derive custom-tool arg1 --foo bar
Calling out to "custom-tool" with ["arg1", "--foo", "bar"] Calling out to "custom-tool" with ["arg1", "--foo", "bar"]
``` ```

View file

@ -3,7 +3,7 @@
Git is an example of several common subcommand patterns. Git is an example of several common subcommand patterns.
Help: Help:
```bash ```console
$ git $ git
? failed ? failed
git git
@ -20,6 +20,7 @@ SUBCOMMANDS:
clone Clones repos clone Clones repos
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
push pushes things push pushes things
$ git help $ git help
git git
A fictional versioning CLI A fictional versioning CLI
@ -35,6 +36,7 @@ SUBCOMMANDS:
clone Clones repos clone Clones repos
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
push pushes things push pushes things
$ git help add $ git help add
git[EXE]-add git[EXE]-add
adds things adds things
@ -47,10 +49,11 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
``` ```
A basic argument: A basic argument:
```bash ```console
$ git add $ git add
? failed ? failed
git[EXE]-add git[EXE]-add
@ -64,12 +67,15 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
$ git add Cargo.toml Cargo.lock $ git add Cargo.toml Cargo.lock
Adding ["Cargo.toml", "Cargo.lock"] Adding ["Cargo.toml", "Cargo.lock"]
``` ```
External subcommands: External subcommands:
```bash ```console
$ git custom-tool arg1 --foo bar $ git custom-tool arg1 --foo bar
Calling out to "custom-tool" with ["arg1", "--foo", "bar"] Calling out to "custom-tool" with ["arg1", "--foo", "bar"]
``` ```

View file

@ -2,7 +2,7 @@
**This requires enabling the `derive` feature flag.** **This requires enabling the `derive` feature flag.**
```bash ```console
$ keyvalue-derive --help $ keyvalue-derive --help
clap clap
@ -12,16 +12,20 @@ USAGE:
OPTIONS: OPTIONS:
-D <DEFINES> -D <DEFINES>
-h, --help Print help information -h, --help Print help information
$ keyvalue-derive -D Foo=10 -D Alice=30 $ keyvalue-derive -D Foo=10 -D Alice=30
Args { defines: [("Foo", 10), ("Alice", 30)] } Args { defines: [("Foo", 10), ("Alice", 30)] }
$ keyvalue-derive -D Foo $ keyvalue-derive -D Foo
? failed ? failed
error: Invalid value for '-D <DEFINES>': invalid KEY=value: no `=` found in `Foo` error: Invalid value for '-D <DEFINES>': invalid KEY=value: no `=` found in `Foo`
For more information try --help For more information try --help
$ keyvalue-derive -D Foo=Bar $ keyvalue-derive -D Foo=Bar
? failed ? failed
error: Invalid value for '-D <DEFINES>': invalid digit found in string error: Invalid value for '-D <DEFINES>': invalid digit found in string
For more information try --help For more information try --help
``` ```

View file

@ -6,24 +6,27 @@ See the documentation for clap::AppSettings::Multicall for rationale.
This example omits every command except true and false, This example omits every command except true and false,
which are the most trivial to implement, which are the most trivial to implement,
```bash ```console
$ busybox true $ busybox true
? 0 ? 0
$ busybox false $ busybox false
? 1 ? 1
``` ```
*Note: without the links setup, we can't demonstrate the multicall behavior* *Note: without the links setup, we can't demonstrate the multicall behavior*
But includes the `--install` option as an example of why it can be useful But includes the `--install` option as an example of why it can be useful
for the main program to take arguments that aren't applet subcommands. for the main program to take arguments that aren't applet subcommands.
```bash ```console
$ busybox --install $ busybox --install
? failed ? failed
... ...
``` ```
Though users must pass something: Though users must pass something:
```bash ```console
$ busybox $ busybox
? failed ? failed
busybox busybox
@ -39,4 +42,5 @@ APPLETS:
false does nothing unsuccessfully false does nothing unsuccessfully
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
true does nothing successfully true does nothing successfully
``` ```

View file

@ -6,8 +6,9 @@ See the documentation for clap::AppSettings::Multicall for rationale.
This example omits the implementation of displaying address config This example omits the implementation of displaying address config
```bash ```console
$ hostname $ hostname
www www
``` ```
*Note: without the links setup, we can't demonstrate the multicall behavior* *Note: without the links setup, we can't demonstrate the multicall behavior*

View file

@ -3,29 +3,34 @@
[`pacman`](https://wiki.archlinux.org/index.php/pacman) defines subcommands via flags. [`pacman`](https://wiki.archlinux.org/index.php/pacman) defines subcommands via flags.
Here, `-S` is a short flag subcommand: Here, `-S` is a short flag subcommand:
```bash ```console
$ pacman -S package $ pacman -S package
Installing package... Installing package...
``` ```
Here `--sync` is a long flag subcommand: Here `--sync` is a long flag subcommand:
```bash ```console
$ pacman --sync package $ pacman --sync package
Installing package... Installing package...
``` ```
Now the short flag subcommand (`-S`) with a long flag: Now the short flag subcommand (`-S`) with a long flag:
```bash ```console
$ pacman -S --search name $ pacman -S --search name
Searching for name... Searching for name...
``` ```
And the various forms of short flags that work: And the various forms of short flags that work:
``` ```console
$ pacman -S -s name $ pacman -S -s name
Searching for name... Searching for name...
$ pacman -Ss name $ pacman -Ss name
Searching for name... Searching for name...
``` ```
*(users can "stack" short subcommands with short flags or with other short flag subcommands)* *(users can "stack" short subcommands with short flags or with other short flag subcommands)*

View file

@ -23,7 +23,7 @@
You can create an application with several arguments using usage strings. You can create an application with several arguments using usage strings.
[Example:](01_quick.rs) [Example:](01_quick.rs)
```bash ```console
$ 01_quick --help $ 01_quick --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -43,19 +43,22 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
test does testing things test does testing things
``` ```
By default, the program does nothing: By default, the program does nothing:
```bash ```console
$ 01_quick $ 01_quick
Debug mode is off Debug mode is off
``` ```
But you can mix and match the various features But you can mix and match the various features
```bash ```console
$ 01_quick -dd test $ 01_quick -dd test
Debug mode is on Debug mode is on
Not printing testing lists... Not printing testing lists...
``` ```
## Configuring the Parser ## Configuring the Parser
@ -63,7 +66,7 @@ Not printing testing lists...
You use the `App` the start building a parser. You use the `App` the start building a parser.
[Example:](02_apps.rs) [Example:](02_apps.rs)
```bash ```console
$ 02_apps --help $ 02_apps --help
MyApp 1.0 MyApp 1.0
Kevin K. <kbknapp@gmail.com> Kevin K. <kbknapp@gmail.com>
@ -77,15 +80,17 @@ OPTIONS:
--one <VALUE> --one <VALUE>
--two <VALUE> --two <VALUE>
-V, --version Print version information -V, --version Print version information
$ 02_apps --version $ 02_apps --version
MyApp 1.0 MyApp 1.0
``` ```
You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml` You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml`
file. **This requires the `cargo` feature flag.** file. **This requires the `cargo` feature flag.**
[Example:](02_crate.rs) [Example:](02_crate.rs)
```bash ```console
$ 02_crate --help $ 02_crate --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -98,8 +103,10 @@ OPTIONS:
--one <VALUE> --one <VALUE>
--two <VALUE> --two <VALUE>
-V, --version Print version information -V, --version Print version information
$ 02_crate --version $ 02_crate --version
clap [..] clap [..]
``` ```
You can use `AppSettings` to change the application level behavior of clap. You You can use `AppSettings` to change the application level behavior of clap. You
@ -107,7 +114,7 @@ can apply the setting to the top level command (`app.setting()`) or to it and
all subcommands (`app.global_setting()`). all subcommands (`app.global_setting()`).
[Example:](02_app_settings.rs) [Example:](02_app_settings.rs)
```bash ```console
$ 02_app_settings --help $ 02_app_settings --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -120,9 +127,11 @@ OPTIONS:
--one <VALUE> --one <VALUE>
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 02_app_settings --one -1 --one -3 --two 10 $ 02_app_settings --one -1 --one -3 --two 10
two: "10" two: "10"
one: "-3" one: "-3"
``` ```
## Adding Arguments ## Adding Arguments
@ -132,7 +141,7 @@ one: "-3"
Flags are switches that can be on/off: Flags are switches that can be on/off:
[Example:](03_01_flag_bool.rs) [Example:](03_01_flag_bool.rs)
```bash ```console
$ 03_01_flag_bool --help $ 03_01_flag_bool --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -144,10 +153,13 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-v, --verbose -v, --verbose
-V, --version Print version information -V, --version Print version information
$ 03_01_flag_bool $ 03_01_flag_bool
verbose: false verbose: false
$ 03_01_flag_bool --verbose $ 03_01_flag_bool --verbose
verbose: true verbose: true
$ 03_01_flag_bool --verbose --verbose $ 03_01_flag_bool --verbose --verbose
? failed ? failed
error: The argument '--verbose' was provided more than once, but cannot be used multiple times error: The argument '--verbose' was provided more than once, but cannot be used multiple times
@ -156,12 +168,13 @@ USAGE:
03_01_flag_bool[EXE] [OPTIONS] 03_01_flag_bool[EXE] [OPTIONS]
For more information try --help For more information try --help
``` ```
Or counted. Or counted.
[Example:](03_01_flag_count.rs) [Example:](03_01_flag_count.rs)
```bash ```console
$ 03_01_flag_count --help $ 03_01_flag_count --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -173,12 +186,16 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-v, --verbose -v, --verbose
-V, --version Print version information -V, --version Print version information
$ 03_01_flag_count $ 03_01_flag_count
verbose: 0 verbose: 0
$ 03_01_flag_count --verbose $ 03_01_flag_count --verbose
verbose: 1 verbose: 1
$ 03_01_flag_count --verbose --verbose $ 03_01_flag_count --verbose --verbose
verbose: 2 verbose: 2
``` ```
### Options ### Options
@ -186,7 +203,7 @@ verbose: 2
Flags can also accept a value. Flags can also accept a value.
[Example:](03_02_option.rs) [Example:](03_02_option.rs)
```bash ```console
$ 03_02_option --help $ 03_02_option --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -198,18 +215,25 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-n, --name <NAME> -n, --name <NAME>
-V, --version Print version information -V, --version Print version information
$ 03_02_option $ 03_02_option
name: None name: None
$ 03_02_option --name bob $ 03_02_option --name bob
name: Some("bob") name: Some("bob")
$ 03_02_option --name=bob $ 03_02_option --name=bob
name: Some("bob") name: Some("bob")
$ 03_02_option -n bob $ 03_02_option -n bob
name: Some("bob") name: Some("bob")
$ 03_02_option -n=bob $ 03_02_option -n=bob
name: Some("bob") name: Some("bob")
$ 03_02_option -nbob $ 03_02_option -nbob
name: Some("bob") name: Some("bob")
``` ```
### Positionals ### Positionals
@ -217,7 +241,7 @@ name: Some("bob")
Or you can have users specify values by their position on the command-line: Or you can have users specify values by their position on the command-line:
[Example:](03_03_positional.rs) [Example:](03_03_positional.rs)
```bash ```console
$ 03_03_positional --help $ 03_03_positional --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -231,10 +255,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 03_03_positional $ 03_03_positional
NAME: None NAME: None
$ 03_03_positional bob $ 03_03_positional bob
NAME: Some("bob") NAME: Some("bob")
``` ```
### Subcommands ### Subcommands
@ -244,7 +271,7 @@ instance of a Subcommand can have its own version, author(s), Args, and even its
subcommands. subcommands.
[Example:](03_04_subcommands.rs) [Example:](03_04_subcommands.rs)
```bash ```console
$ 03_04_subcommands $ 03_04_subcommands
? failed ? failed
clap [..] clap [..]
@ -260,6 +287,7 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
add Adds files to myapp add Adds files to myapp
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
$ 03_04_subcommands help $ 03_04_subcommands help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -274,6 +302,7 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
add Adds files to myapp add Adds files to myapp
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
$ 03_04_subcommands help add $ 03_04_subcommands help add
03_04_subcommands[EXE]-add [..] 03_04_subcommands[EXE]-add [..]
Adds files to myapp Adds files to myapp
@ -287,16 +316,20 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 03_04_subcommands add bob $ 03_04_subcommands add bob
'myapp add' was used, name is: Some("bob") 'myapp add' was used, name is: Some("bob")
``` ```
Because we set `AppSettings::PropagateVersion`: Because we set `AppSettings::PropagateVersion`:
```bash ```console
$ 03_04_subcommands --version $ 03_04_subcommands --version
clap [..] clap [..]
$ 03_04_subcommands add --version $ 03_04_subcommands add --version
03_04_subcommands[EXE]-add [..] 03_04_subcommands[EXE]-add [..]
``` ```
### Defaults ### Defaults
@ -306,7 +339,7 @@ optional, you work with a `Option` and can `unwrap_or`. Alternatively, you can
set `Arg::default_value`. set `Arg::default_value`.
[Example:](03_05_default_values.rs) [Example:](03_05_default_values.rs)
```bash ```console
$ 03_05_default_values --help $ 03_05_default_values --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -320,10 +353,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 03_05_default_values $ 03_05_default_values
NAME: "alice" NAME: "alice"
$ 03_05_default_values bob $ 03_05_default_values bob
NAME: "bob" NAME: "bob"
``` ```
## Validation ## Validation
@ -338,7 +374,7 @@ those specific values, they will receive a graceful exit with error message info
of the mistake, and what the possible valid values are of the mistake, and what the possible valid values are
[Example:](04_01_possible.rs) [Example:](04_01_possible.rs)
```bash ```console
$ 04_01_possible --help $ 04_01_possible --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -352,10 +388,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 04_01_possible fast $ 04_01_possible fast
Hare Hare
$ 04_01_possible slow $ 04_01_possible slow
Tortoise Tortoise
$ 04_01_possible medium $ 04_01_possible medium
? failed ? failed
error: "medium" isn't a valid value for '<MODE>' error: "medium" isn't a valid value for '<MODE>'
@ -365,12 +404,13 @@ USAGE:
04_01_possible[EXE] <MODE> 04_01_possible[EXE] <MODE>
For more information try --help For more information try --help
``` ```
When enabling the `derive` feature, you can use `ArgEnum` to take care of the boiler plate for you, giving the same results. When enabling the `derive` feature, you can use `ArgEnum` to take care of the boiler plate for you, giving the same results.
[Example:](04_01_enum.rs) [Example:](04_01_enum.rs)
```bash ```console
$ 04_01_enum --help $ 04_01_enum --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -384,10 +424,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 04_01_enum fast $ 04_01_enum fast
Hare Hare
$ 04_01_enum slow $ 04_01_enum slow
Tortoise Tortoise
$ 04_01_enum medium $ 04_01_enum medium
? failed ? failed
error: "medium" isn't a valid value for '<MODE>' error: "medium" isn't a valid value for '<MODE>'
@ -397,6 +440,7 @@ USAGE:
04_01_enum[EXE] <MODE> 04_01_enum[EXE] <MODE>
For more information try --help For more information try --help
``` ```
### Validated values ### Validated values
@ -404,7 +448,7 @@ For more information try --help
More generally, you can validate and parse into any data type. More generally, you can validate and parse into any data type.
[Example:](04_02_validate.rs) [Example:](04_02_validate.rs)
```bash ```console
$ 04_02_validate --help $ 04_02_validate --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -418,13 +462,16 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 04_02_validate 22 $ 04_02_validate 22
PORT = 22 PORT = 22
$ 04_02_validate foobar $ 04_02_validate foobar
? failed ? failed
error: Invalid value for '<PORT>': invalid digit found in string error: Invalid value for '<PORT>': invalid digit found in string
For more information try --help For more information try --help
``` ```
### Argument Relations ### Argument Relations
@ -440,7 +487,7 @@ be required, but making all of them required isn't feasible because perhaps they
each other. each other.
[Example:](04_03_relations.rs) [Example:](04_03_relations.rs)
```bash ```console
$ 04_03_relations --help $ 04_03_relations --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -460,6 +507,7 @@ OPTIONS:
--set-ver <VER> set version manually --set-ver <VER> set version manually
--spec-in <SPEC_IN> some special input argument --spec-in <SPEC_IN> some special input argument
-V, --version Print version information -V, --version Print version information
$ 04_03_relations $ 04_03_relations
? failed ? failed
error: The following required arguments were not provided: error: The following required arguments were not provided:
@ -469,8 +517,10 @@ USAGE:
04_03_relations[EXE] [OPTIONS] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE] 04_03_relations[EXE] [OPTIONS] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE]
For more information try --help For more information try --help
$ 04_03_relations --major $ 04_03_relations --major
Version: 2.2.3 Version: 2.2.3
$ 04_03_relations --major --minor $ 04_03_relations --major --minor
? failed ? failed
error: The argument '--major' cannot be used with '--minor' error: The argument '--major' cannot be used with '--minor'
@ -479,6 +529,7 @@ USAGE:
04_03_relations[EXE] <--set-ver <VER>|--major|--minor|--patch> 04_03_relations[EXE] <--set-ver <VER>|--major|--minor|--patch>
For more information try --help For more information try --help
$ 04_03_relations --major -c config.toml $ 04_03_relations --major -c config.toml
? failed ? failed
error: The following required arguments were not provided: error: The following required arguments were not provided:
@ -488,9 +539,11 @@ USAGE:
04_03_relations[EXE] -c <CONFIG> <--set-ver <VER>|--major|--minor|--patch> <INPUT_FILE|--spec-in <SPEC_IN>> 04_03_relations[EXE] -c <CONFIG> <--set-ver <VER>|--major|--minor|--patch> <INPUT_FILE|--spec-in <SPEC_IN>>
For more information try --help For more information try --help
$ 04_03_relations --major -c config.toml --spec-in input.txt $ 04_03_relations --major -c config.toml --spec-in input.txt
Version: 2.2.3 Version: 2.2.3
Doing work using input input.txt and config config.toml Doing work using input input.txt and config config.toml
``` ```
### Custom Validation ### Custom Validation
@ -498,7 +551,7 @@ Doing work using input input.txt and config config.toml
As a last resort, you can create custom errors with the basics of clap's formatting. As a last resort, you can create custom errors with the basics of clap's formatting.
[Example:](04_04_custom.rs) [Example:](04_04_custom.rs)
```bash ```console
$ 04_04_custom --help $ 04_04_custom --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -518,6 +571,7 @@ OPTIONS:
--set-ver <VER> set version manually --set-ver <VER> set version manually
--spec-in <SPEC_IN> some special input argument --spec-in <SPEC_IN> some special input argument
-V, --version Print version information -V, --version Print version information
$ 04_04_custom $ 04_04_custom
? failed ? failed
error: Cam only modify one version field error: Cam only modify one version field
@ -526,8 +580,10 @@ USAGE:
04_04_custom[EXE] [OPTIONS] [INPUT_FILE] 04_04_custom[EXE] [OPTIONS] [INPUT_FILE]
For more information try --help For more information try --help
$ 04_04_custom --major $ 04_04_custom --major
Version: 2.2.3 Version: 2.2.3
$ 04_04_custom --major --minor $ 04_04_custom --major --minor
? failed ? failed
error: Cam only modify one version field error: Cam only modify one version field
@ -536,6 +592,7 @@ USAGE:
04_04_custom[EXE] [OPTIONS] [INPUT_FILE] 04_04_custom[EXE] [OPTIONS] [INPUT_FILE]
For more information try --help For more information try --help
$ 04_04_custom --major -c config.toml $ 04_04_custom --major -c config.toml
? failed ? failed
Version: 2.2.3 Version: 2.2.3
@ -545,9 +602,11 @@ USAGE:
04_04_custom[EXE] [OPTIONS] [INPUT_FILE] 04_04_custom[EXE] [OPTIONS] [INPUT_FILE]
For more information try --help For more information try --help
$ 04_04_custom --major -c config.toml --spec-in input.txt $ 04_04_custom --major -c config.toml --spec-in input.txt
Version: 2.2.3 Version: 2.2.3
Doing work using input input.txt and config config.toml Doing work using input input.txt and config config.toml
``` ```
## Tips ## Tips

View file

@ -24,7 +24,7 @@ You can create an application declaratively with a `struct` and some
attributes. **This requires enabling the `derive` feature flag.** attributes. **This requires enabling the `derive` feature flag.**
[Example:](01_quick.rs) [Example:](01_quick.rs)
```bash ```console
$ 01_quick_derive --help $ 01_quick_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -44,19 +44,22 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
test does testing things test does testing things
``` ```
By default, the program does nothing: By default, the program does nothing:
```bash ```console
$ 01_quick_derive $ 01_quick_derive
Debug mode is off Debug mode is off
``` ```
But you can mix and match the various features But you can mix and match the various features
```bash ```console
$ 01_quick_derive -dd test $ 01_quick_derive -dd test
Debug mode is on Debug mode is on
Not printing testing lists... Not printing testing lists...
``` ```
## Configuring the Parser ## Configuring the Parser
@ -64,7 +67,7 @@ Not printing testing lists...
You use the `App` the start building a parser. You use the `App` the start building a parser.
[Example:](02_apps.rs) [Example:](02_apps.rs)
```bash ```console
$ 02_apps_derive --help $ 02_apps_derive --help
MyApp 1.0 MyApp 1.0
Kevin K. <kbknapp@gmail.com> Kevin K. <kbknapp@gmail.com>
@ -78,14 +81,16 @@ OPTIONS:
--one <ONE> --one <ONE>
--two <TWO> --two <TWO>
-V, --version Print version information -V, --version Print version information
$ 02_apps_derive --version $ 02_apps_derive --version
MyApp 1.0 MyApp 1.0
``` ```
You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml` file. You can use `app_from_crate!()` to fill these fields in from your `Cargo.toml` file.
[Example:](02_crate.rs) [Example:](02_crate.rs)
```bash ```console
$ 02_crate_derive --help $ 02_crate_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -98,8 +103,10 @@ OPTIONS:
--one <ONE> --one <ONE>
--two <TWO> --two <TWO>
-V, --version Print version information -V, --version Print version information
$ 02_crate_derive --version $ 02_crate_derive --version
clap [..] clap [..]
``` ```
You can use `AppSettings` to change the application level behavior of clap. You You can use `AppSettings` to change the application level behavior of clap. You
@ -107,7 +114,7 @@ can apply the setting to the top level command (`app.setting()`) or to it and
all subcommands (`app.global_setting()`). all subcommands (`app.global_setting()`).
[Example:](02_app_settings.rs) [Example:](02_app_settings.rs)
```bash ```console
$ 02_app_settings_derive --help $ 02_app_settings_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -120,9 +127,11 @@ OPTIONS:
--one <ONE> --one <ONE>
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 02_app_settings_derive --one -1 --one -3 --two 10 $ 02_app_settings_derive --one -1 --one -3 --two 10
two: "10" two: "10"
one: "-3" one: "-3"
``` ```
## Adding Arguments ## Adding Arguments
@ -132,7 +141,7 @@ one: "-3"
Flags are switches that can be on/off: Flags are switches that can be on/off:
[Example:](03_01_flag_bool.rs) [Example:](03_01_flag_bool.rs)
```bash ```console
$ 03_01_flag_bool_derive --help $ 03_01_flag_bool_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -144,10 +153,13 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-v, --verbose -v, --verbose
-V, --version Print version information -V, --version Print version information
$ 03_01_flag_bool_derive $ 03_01_flag_bool_derive
verbose: false verbose: false
$ 03_01_flag_bool_derive --verbose $ 03_01_flag_bool_derive --verbose
verbose: true verbose: true
$ 03_01_flag_bool_derive --verbose --verbose $ 03_01_flag_bool_derive --verbose --verbose
? failed ? failed
error: The argument '--verbose' was provided more than once, but cannot be used multiple times error: The argument '--verbose' was provided more than once, but cannot be used multiple times
@ -156,12 +168,13 @@ USAGE:
03_01_flag_bool_derive[EXE] [OPTIONS] 03_01_flag_bool_derive[EXE] [OPTIONS]
For more information try --help For more information try --help
``` ```
Or counted. Or counted.
[Example:](03_01_flag_count.rs) [Example:](03_01_flag_count.rs)
```bash ```console
$ 03_01_flag_count_derive --help $ 03_01_flag_count_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -173,12 +186,16 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-v, --verbose -v, --verbose
-V, --version Print version information -V, --version Print version information
$ 03_01_flag_count_derive $ 03_01_flag_count_derive
verbose: 0 verbose: 0
$ 03_01_flag_count_derive --verbose $ 03_01_flag_count_derive --verbose
verbose: 1 verbose: 1
$ 03_01_flag_count_derive --verbose --verbose $ 03_01_flag_count_derive --verbose --verbose
verbose: 2 verbose: 2
``` ```
### Options ### Options
@ -186,7 +203,7 @@ verbose: 2
Flags can also accept a value. Flags can also accept a value.
[Example:](03_02_option.rs) [Example:](03_02_option.rs)
```bash ```console
$ 03_02_option_derive --help $ 03_02_option_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -198,18 +215,25 @@ OPTIONS:
-h, --help Print help information -h, --help Print help information
-n, --name <NAME> -n, --name <NAME>
-V, --version Print version information -V, --version Print version information
$ 03_02_option_derive $ 03_02_option_derive
name: None name: None
$ 03_02_option_derive --name bob $ 03_02_option_derive --name bob
name: Some("bob") name: Some("bob")
$ 03_02_option_derive --name=bob $ 03_02_option_derive --name=bob
name: Some("bob") name: Some("bob")
$ 03_02_option_derive -n bob $ 03_02_option_derive -n bob
name: Some("bob") name: Some("bob")
$ 03_02_option_derive -n=bob $ 03_02_option_derive -n=bob
name: Some("bob") name: Some("bob")
$ 03_02_option_derive -nbob $ 03_02_option_derive -nbob
name: Some("bob") name: Some("bob")
``` ```
### Positionals ### Positionals
@ -217,7 +241,7 @@ name: Some("bob")
Or you can have users specify values by their position on the command-line: Or you can have users specify values by their position on the command-line:
[Example:](03_03_positional.rs) [Example:](03_03_positional.rs)
```bash ```console
$ 03_03_positional_derive --help $ 03_03_positional_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -231,10 +255,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 03_03_positional_derive $ 03_03_positional_derive
name: None name: None
$ 03_03_positional_derive bob $ 03_03_positional_derive bob
name: Some("bob") name: Some("bob")
``` ```
### Subcommands ### Subcommands
@ -244,7 +271,7 @@ instance of a Subcommand can have its own version, author(s), Args, and even its
subcommands. subcommands.
[Example:](03_04_subcommands.rs) [Example:](03_04_subcommands.rs)
```bash ```console
$ 03_04_subcommands_derive $ 03_04_subcommands_derive
? failed ? failed
clap [..] clap [..]
@ -260,6 +287,7 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
add Adds files to myapp add Adds files to myapp
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
$ 03_04_subcommands_derive help $ 03_04_subcommands_derive help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -274,6 +302,7 @@ OPTIONS:
SUBCOMMANDS: SUBCOMMANDS:
add Adds files to myapp add Adds files to myapp
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
$ 03_04_subcommands_derive help add $ 03_04_subcommands_derive help add
03_04_subcommands_derive[EXE]-add [..] 03_04_subcommands_derive[EXE]-add [..]
Adds files to myapp Adds files to myapp
@ -287,16 +316,20 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 03_04_subcommands_derive add bob $ 03_04_subcommands_derive add bob
'myapp add' was used, name is: Some("bob") 'myapp add' was used, name is: Some("bob")
``` ```
Because we set `AppSettings::PropagateVersion`: Because we set `AppSettings::PropagateVersion`:
```bash ```console
$ 03_04_subcommands_derive --version $ 03_04_subcommands_derive --version
clap [..] clap [..]
$ 03_04_subcommands_derive add --version $ 03_04_subcommands_derive add --version
03_04_subcommands_derive[EXE]-add [..] 03_04_subcommands_derive[EXE]-add [..]
``` ```
### Defaults ### Defaults
@ -306,7 +339,7 @@ optional, you work with a `Option` and can `unwrap_or`. Alternatively, you can
set `Arg::default_value`. set `Arg::default_value`.
[Example:](03_05_default_values.rs) [Example:](03_05_default_values.rs)
```bash ```console
$ 03_05_default_values_derive --help $ 03_05_default_values_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -320,10 +353,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 03_05_default_values_derive $ 03_05_default_values_derive
name: "alice" name: "alice"
$ 03_05_default_values_derive bob $ 03_05_default_values_derive bob
name: "bob" name: "bob"
``` ```
## Validation ## Validation
@ -338,7 +374,7 @@ those specific values, they will receive a graceful exit with error message info
of the mistake, and what the possible valid values are of the mistake, and what the possible valid values are
[Example:](04_01_enum.rs) [Example:](04_01_enum.rs)
```bash ```console
$ 04_01_enum_derive --help $ 04_01_enum_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -352,10 +388,13 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 04_01_enum_derive fast $ 04_01_enum_derive fast
Hare Hare
$ 04_01_enum_derive slow $ 04_01_enum_derive slow
Tortoise Tortoise
$ 04_01_enum_derive medium $ 04_01_enum_derive medium
? failed ? failed
error: "medium" isn't a valid value for '<MODE>' error: "medium" isn't a valid value for '<MODE>'
@ -365,6 +404,7 @@ USAGE:
04_01_enum_derive[EXE] <MODE> 04_01_enum_derive[EXE] <MODE>
For more information try --help For more information try --help
``` ```
### Validated values ### Validated values
@ -372,7 +412,7 @@ For more information try --help
More generally, you can validate and parse into any data type. More generally, you can validate and parse into any data type.
[Example:](04_02_validate.rs) [Example:](04_02_validate.rs)
```bash ```console
$ 04_02_validate_derive --help $ 04_02_validate_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -386,13 +426,16 @@ ARGS:
OPTIONS: OPTIONS:
-h, --help Print help information -h, --help Print help information
-V, --version Print version information -V, --version Print version information
$ 04_02_validate_derive 22 $ 04_02_validate_derive 22
PORT = 22 PORT = 22
$ 04_02_validate_derive foobar $ 04_02_validate_derive foobar
? failed ? failed
error: Invalid value for '<PORT>': invalid digit found in string error: Invalid value for '<PORT>': invalid digit found in string
For more information try --help For more information try --help
``` ```
### Argument Relations ### Argument Relations
@ -408,7 +451,7 @@ be required, but making all of them required isn't feasible because perhaps they
each other. each other.
[Example:](04_03_relations.rs) [Example:](04_03_relations.rs)
```bash ```console
$ 04_03_relations_derive --help $ 04_03_relations_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -428,6 +471,7 @@ OPTIONS:
--set-ver <VER> set version manually --set-ver <VER> set version manually
--spec-in <SPEC_IN> some special input argument --spec-in <SPEC_IN> some special input argument
-V, --version Print version information -V, --version Print version information
$ 04_03_relations_derive $ 04_03_relations_derive
? failed ? failed
error: The following required arguments were not provided: error: The following required arguments were not provided:
@ -437,8 +481,10 @@ USAGE:
04_03_relations_derive[EXE] [OPTIONS] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE] 04_03_relations_derive[EXE] [OPTIONS] <--set-ver <VER>|--major|--minor|--patch> [INPUT_FILE]
For more information try --help For more information try --help
$ 04_03_relations_derive --major $ 04_03_relations_derive --major
Version: 2.2.3 Version: 2.2.3
$ 04_03_relations_derive --major --minor $ 04_03_relations_derive --major --minor
? failed ? failed
error: The argument '--major' cannot be used with '--minor' error: The argument '--major' cannot be used with '--minor'
@ -447,6 +493,7 @@ USAGE:
04_03_relations_derive[EXE] <--set-ver <VER>|--major|--minor|--patch> 04_03_relations_derive[EXE] <--set-ver <VER>|--major|--minor|--patch>
For more information try --help For more information try --help
$ 04_03_relations_derive --major -c config.toml $ 04_03_relations_derive --major -c config.toml
? failed ? failed
error: The following required arguments were not provided: error: The following required arguments were not provided:
@ -456,9 +503,11 @@ USAGE:
04_03_relations_derive[EXE] -c <CONFIG> <--set-ver <VER>|--major|--minor|--patch> <INPUT_FILE|--spec-in <SPEC_IN>> 04_03_relations_derive[EXE] -c <CONFIG> <--set-ver <VER>|--major|--minor|--patch> <INPUT_FILE|--spec-in <SPEC_IN>>
For more information try --help For more information try --help
$ 04_03_relations_derive --major -c config.toml --spec-in input.txt $ 04_03_relations_derive --major -c config.toml --spec-in input.txt
Version: 2.2.3 Version: 2.2.3
Doing work using input input.txt and config config.toml Doing work using input input.txt and config config.toml
``` ```
### Custom Validation ### Custom Validation
@ -466,7 +515,7 @@ Doing work using input input.txt and config config.toml
As a last resort, you can create custom errors with the basics of clap's formatting. As a last resort, you can create custom errors with the basics of clap's formatting.
[Example:](04_04_custom.rs) [Example:](04_04_custom.rs)
```bash ```console
$ 04_04_custom_derive --help $ 04_04_custom_derive --help
clap [..] clap [..]
A simple to use, efficient, and full-featured Command Line Argument Parser A simple to use, efficient, and full-featured Command Line Argument Parser
@ -486,6 +535,7 @@ OPTIONS:
--set-ver <VER> set version manually --set-ver <VER> set version manually
--spec-in <SPEC_IN> some special input argument --spec-in <SPEC_IN> some special input argument
-V, --version Print version information -V, --version Print version information
$ 04_04_custom_derive $ 04_04_custom_derive
? failed ? failed
error: Cam only modify one version field error: Cam only modify one version field
@ -494,8 +544,10 @@ USAGE:
clap [OPTIONS] [INPUT_FILE] clap [OPTIONS] [INPUT_FILE]
For more information try --help For more information try --help
$ 04_04_custom_derive --major $ 04_04_custom_derive --major
Version: 2.2.3 Version: 2.2.3
$ 04_04_custom_derive --major --minor $ 04_04_custom_derive --major --minor
? failed ? failed
error: Cam only modify one version field error: Cam only modify one version field
@ -504,6 +556,7 @@ USAGE:
clap [OPTIONS] [INPUT_FILE] clap [OPTIONS] [INPUT_FILE]
For more information try --help For more information try --help
$ 04_04_custom_derive --major -c config.toml $ 04_04_custom_derive --major -c config.toml
? failed ? failed
Version: 2.2.3 Version: 2.2.3
@ -513,9 +566,11 @@ USAGE:
clap [OPTIONS] [INPUT_FILE] clap [OPTIONS] [INPUT_FILE]
For more information try --help For more information try --help
$ 04_04_custom_derive --major -c config.toml --spec-in input.txt $ 04_04_custom_derive --major -c config.toml --spec-in input.txt
Version: 2.2.3 Version: 2.2.3
Doing work using input input.txt and config config.toml Doing work using input input.txt and config config.toml
``` ```
## Tips ## Tips