docs(examples): Show implicit parser

This commit is contained in:
Ed Page 2022-03-14 09:43:17 -05:00
parent a8ffebbab9
commit ce9e2cba8f
2 changed files with 27 additions and 3 deletions

View file

@ -2,6 +2,7 @@
**This requires enabling the `derive` feature flag.**
Help:
```console
$ typed-derive --help
clap
@ -10,11 +11,29 @@ USAGE:
typed-derive[EXE] [OPTIONS]
OPTIONS:
-D <DEFINES>
-h, --help Print help information
-D <DEFINES> Hand-written parser for tuples
-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
Args { defines: [("Foo", 10), ("Alice", 30)] }
Args { optimization: None, defines: [("Foo", 10), ("Alice", 30)] }
$ typed-derive -D Foo
? failed

View file

@ -5,6 +5,11 @@ use std::error::Error;
#[derive(Parser, Debug)]
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))]
defines: Vec<(String, i32)>,
}