mirror of
https://github.com/clap-rs/clap
synced 2024-12-13 14:22:34 +00:00
docs(examples): Show implicit parser
This commit is contained in:
parent
a8ffebbab9
commit
ce9e2cba8f
2 changed files with 27 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
**This requires enabling the `derive` feature flag.**
|
**This requires enabling the `derive` feature flag.**
|
||||||
|
|
||||||
|
Help:
|
||||||
```console
|
```console
|
||||||
$ typed-derive --help
|
$ typed-derive --help
|
||||||
clap
|
clap
|
||||||
|
@ -10,11 +11,29 @@ USAGE:
|
||||||
typed-derive[EXE] [OPTIONS]
|
typed-derive[EXE] [OPTIONS]
|
||||||
|
|
||||||
OPTIONS:
|
OPTIONS:
|
||||||
-D <DEFINES>
|
-D <DEFINES> Hand-written parser for tuples
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
|
-O <OPTIMIZATION> Implicitly using `std::str::FromStr`
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Optimization-level (number)
|
||||||
|
```console
|
||||||
|
$ typed-derive -O 1
|
||||||
|
Args { optimization: Some(1), defines: [] }
|
||||||
|
|
||||||
|
$ typed-derive -O plaid
|
||||||
|
? failed
|
||||||
|
error: Invalid value "plaid" for '-O <OPTIMIZATION>': invalid digit found in string
|
||||||
|
|
||||||
|
For more information try --help
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Defines (key-value pairs)
|
||||||
|
```console
|
||||||
$ typed-derive -D Foo=10 -D Alice=30
|
$ typed-derive -D Foo=10 -D Alice=30
|
||||||
Args { defines: [("Foo", 10), ("Alice", 30)] }
|
Args { optimization: None, defines: [("Foo", 10), ("Alice", 30)] }
|
||||||
|
|
||||||
$ typed-derive -D Foo
|
$ typed-derive -D Foo
|
||||||
? failed
|
? failed
|
||||||
|
|
|
@ -5,6 +5,11 @@ use std::error::Error;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
/// Implicitly using `std::str::FromStr`
|
||||||
|
#[clap(short = 'O')]
|
||||||
|
optimization: Option<usize>,
|
||||||
|
|
||||||
|
/// Hand-written parser for tuples
|
||||||
#[clap(short = 'D', parse(try_from_str = parse_key_val), multiple_occurrences(true))]
|
#[clap(short = 'D', parse(try_from_str = parse_key_val), multiple_occurrences(true))]
|
||||||
defines: Vec<(String, i32)>,
|
defines: Vec<(String, i32)>,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue