mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 06:42:33 +00:00
docs(examples): Show duration parsing
This commit is contained in:
parent
c230c72120
commit
4842f07045
3 changed files with 22 additions and 3 deletions
|
@ -140,6 +140,7 @@ trybuild = "1.0.18"
|
||||||
rustversion = "1"
|
rustversion = "1"
|
||||||
# Cutting out `filesystem` feature
|
# Cutting out `filesystem` feature
|
||||||
trycmd = { version = "0.13", default-features = false, features = ["color-auto", "diff", "examples"] }
|
trycmd = { version = "0.13", default-features = false, features = ["color-auto", "diff", "examples"] }
|
||||||
|
humantime = "2"
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "demo"
|
name = "demo"
|
||||||
|
|
|
@ -15,13 +15,14 @@ OPTIONS:
|
||||||
-h, --help Print help information
|
-h, --help Print help information
|
||||||
-I <DIR> Allow invalid UTF-8 paths
|
-I <DIR> Allow invalid UTF-8 paths
|
||||||
-O <OPTIMIZATION> Implicitly using `std::str::FromStr`
|
-O <OPTIMIZATION> Implicitly using `std::str::FromStr`
|
||||||
|
--sleep <SLEEP> Allow human-readable durations
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Optimization-level (number)
|
Optimization-level (number)
|
||||||
```console
|
```console
|
||||||
$ typed-derive -O 1
|
$ typed-derive -O 1
|
||||||
Args { optimization: Some(1), include: None, defines: [] }
|
Args { optimization: Some(1), include: None, sleep: None, defines: [] }
|
||||||
|
|
||||||
$ typed-derive -O plaid
|
$ typed-derive -O plaid
|
||||||
? failed
|
? failed
|
||||||
|
@ -34,14 +35,27 @@ For more information try --help
|
||||||
Include (path)
|
Include (path)
|
||||||
```console
|
```console
|
||||||
$ typed-derive -I../hello
|
$ typed-derive -I../hello
|
||||||
Args { optimization: None, include: Some("../hello"), defines: [] }
|
Args { optimization: None, include: Some("../hello"), sleep: None, defines: [] }
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
Time
|
||||||
|
```console
|
||||||
|
$ typed-derive --sleep 10s
|
||||||
|
Args { optimization: None, include: None, sleep: Some(Duration(10s)), defines: [] }
|
||||||
|
|
||||||
|
$ typed-derive --sleep forever
|
||||||
|
? failed
|
||||||
|
error: Invalid value "forever" for '--sleep <SLEEP>': expected number at 0
|
||||||
|
|
||||||
|
For more information try --help
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Defines (key-value pairs)
|
Defines (key-value pairs)
|
||||||
```console
|
```console
|
||||||
$ typed-derive -D Foo=10 -D Alice=30
|
$ typed-derive -D Foo=10 -D Alice=30
|
||||||
Args { optimization: None, include: None, defines: [("Foo", 10), ("Alice", 30)] }
|
Args { optimization: None, include: None, sleep: None, defines: [("Foo", 10), ("Alice", 30)] }
|
||||||
|
|
||||||
$ typed-derive -D Foo
|
$ typed-derive -D Foo
|
||||||
? failed
|
? failed
|
||||||
|
|
|
@ -13,6 +13,10 @@ struct Args {
|
||||||
#[clap(short = 'I', parse(from_os_str), value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
|
#[clap(short = 'I', parse(from_os_str), value_name = "DIR", value_hint = clap::ValueHint::DirPath)]
|
||||||
include: Option<std::path::PathBuf>,
|
include: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
|
/// Allow human-readable durations
|
||||||
|
#[clap(long)]
|
||||||
|
sleep: Option<humantime::Duration>,
|
||||||
|
|
||||||
/// Hand-written parser for tuples
|
/// 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