mirror of
https://github.com/clap-rs/clap
synced 2025-03-05 07:47:40 +00:00
parent
de7fc7a08e
commit
18192d8e50
8 changed files with 41 additions and 18 deletions
|
@ -1,6 +1,7 @@
|
||||||
language: rust
|
language: rust
|
||||||
cache: cargo
|
cache: cargo
|
||||||
rust:
|
rust:
|
||||||
|
- 1.21.0
|
||||||
- stable
|
- stable
|
||||||
- beta
|
- beta
|
||||||
- nightly
|
- nightly
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
# v0.2.10 (2018-06-07)
|
||||||
|
|
||||||
|
* 1.21.0 is the minimum required rustc version by
|
||||||
|
[@TeXitoi](https://github.com/TeXitoi)
|
||||||
|
|
||||||
# v0.2.9 (2018-06-05)
|
# v0.2.9 (2018-06-05)
|
||||||
|
|
||||||
* Fix a bug when using `flatten` by
|
* Fix a bug when using `flatten` by
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "structopt"
|
name = "structopt"
|
||||||
version = "0.2.9"
|
version = "0.2.10"
|
||||||
authors = ["Guillaume Pinot <texitoi@texitoi.eu>", "others"]
|
authors = ["Guillaume Pinot <texitoi@texitoi.eu>", "others"]
|
||||||
description = "Parse command line argument by defining a struct."
|
description = "Parse command line argument by defining a struct."
|
||||||
documentation = "https://docs.rs/structopt"
|
documentation = "https://docs.rs/structopt"
|
||||||
|
@ -27,6 +27,6 @@ travis-ci = { repository = "TeXitoi/structopt" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = { version = "2.20", default-features = false }
|
clap = { version = "2.20", default-features = false }
|
||||||
structopt-derive = { path = "structopt-derive", version = "0.2.9" }
|
structopt-derive = { path = "structopt-derive", version = "0.2.10" }
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -102,6 +102,12 @@ $ ./basic -o foo.txt -dvvvs 1337 -l alice -l bob --nb-cars 4 bar.txt baz.txt
|
||||||
Opt { debug: true, verbose: 3, speed: 1337, output: "foo.txt", nb_cars: Some(4), level: ["alice", "bob"], files: ["bar.txt", "baz.txt"] }
|
Opt { debug: true, verbose: 3, speed: 1337, output: "foo.txt", nb_cars: Some(4), level: ["alice", "bob"], files: ["bar.txt", "baz.txt"] }
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## StructOpt rustc version policy
|
||||||
|
|
||||||
|
- Minimum rustc version modification must be specified in the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md) and in the [travis configuration](https://github.com/TeXitoi/structopt/blob/master/.travis.yml).
|
||||||
|
- Contributors can increment minimum rustc version without any justification if the new version is required by the latest version of one of StructOpt's depedencies (`cargo update` will not fail on StructOpt).
|
||||||
|
- Contributors can increment minimum rustc version if the library user experience is improved.
|
||||||
|
|
||||||
## Why
|
## Why
|
||||||
|
|
||||||
I use [docopt](https://crates.io/crates/docopt) since a long time (pre rust 1.0). I really like the fact that you have a structure with the parsed argument: no need to convert `String` to `f64`, no useless `unwrap`. But on the other hand, I don't like to write by hand the usage string. That's like going back to the golden age of WYSIWYG editors. Field naming is also a bit artificial.
|
I use [docopt](https://crates.io/crates/docopt) since a long time (pre rust 1.0). I really like the fact that you have a structure with the parsed argument: no need to convert `String` to `f64`, no useless `unwrap`. But on the other hand, I don't like to write by hand the usage string. That's like going back to the golden age of WYSIWYG editors. Field naming is also a bit artificial.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "structopt-derive"
|
name = "structopt-derive"
|
||||||
version = "0.2.9"
|
version = "0.2.10"
|
||||||
authors = ["Guillaume Pinot <texitoi@texitoi.eu>"]
|
authors = ["Guillaume Pinot <texitoi@texitoi.eu>"]
|
||||||
description = "Parse command line argument by defining a struct, derive crate."
|
description = "Parse command line argument by defining a struct, derive crate."
|
||||||
documentation = "https://docs.rs/structopt-derive"
|
documentation = "https://docs.rs/structopt-derive"
|
||||||
|
|
|
@ -108,7 +108,7 @@ impl Attrs {
|
||||||
ref tokens => panic!("unsupported syntax: {}", quote!(#tokens).to_string()),
|
ref tokens => panic!("unsupported syntax: {}", quote!(#tokens).to_string()),
|
||||||
});
|
});
|
||||||
for attr in iter {
|
for attr in iter {
|
||||||
match &attr {
|
match attr {
|
||||||
NameValue(MetaNameValue {
|
NameValue(MetaNameValue {
|
||||||
ident,
|
ident,
|
||||||
lit: Str(value),
|
lit: Str(value),
|
||||||
|
@ -118,14 +118,21 @@ impl Attrs {
|
||||||
name: ident.to_string(),
|
name: ident.to_string(),
|
||||||
args: quote!(#lit),
|
args: quote!(#lit),
|
||||||
}),
|
}),
|
||||||
List(MetaList { ident, nested, .. }) if ident == "parse" => {
|
List(MetaList {
|
||||||
|
ref ident,
|
||||||
|
ref nested,
|
||||||
|
..
|
||||||
|
}) if ident == "parse" =>
|
||||||
|
{
|
||||||
if nested.len() != 1 {
|
if nested.len() != 1 {
|
||||||
panic!("parse must have exactly one argument");
|
panic!("parse must have exactly one argument");
|
||||||
}
|
}
|
||||||
self.has_custom_parser = true;
|
self.has_custom_parser = true;
|
||||||
self.parser = match &nested[0] {
|
self.parser = match nested[0] {
|
||||||
Meta(NameValue(MetaNameValue {
|
Meta(NameValue(MetaNameValue {
|
||||||
ident, lit: Str(v), ..
|
ref ident,
|
||||||
|
lit: Str(ref v),
|
||||||
|
..
|
||||||
})) => {
|
})) => {
|
||||||
let function: syn::Path = v.parse().expect("parser function path");
|
let function: syn::Path = v.parse().expect("parser function path");
|
||||||
let parser = ident.to_string().parse().unwrap();
|
let parser = ident.to_string().parse().unwrap();
|
||||||
|
@ -149,13 +156,17 @@ impl Attrs {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
List(MetaList {
|
List(MetaList {
|
||||||
ident, ref nested, ..
|
ref ident,
|
||||||
|
ref nested,
|
||||||
|
..
|
||||||
}) if ident == "raw" =>
|
}) if ident == "raw" =>
|
||||||
{
|
{
|
||||||
for method in nested {
|
for method in nested {
|
||||||
match method {
|
match *method {
|
||||||
Meta(NameValue(MetaNameValue {
|
Meta(NameValue(MetaNameValue {
|
||||||
ident, lit: Str(v), ..
|
ref ident,
|
||||||
|
lit: Str(ref v),
|
||||||
|
..
|
||||||
})) => self.push_raw_method(&ident.to_string(), v),
|
})) => self.push_raw_method(&ident.to_string(), v),
|
||||||
ref mi @ _ => panic!("unsupported raw entry: {}", quote!(#mi)),
|
ref mi @ _ => panic!("unsupported raw entry: {}", quote!(#mi)),
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,6 +106,6 @@ fn arguments_safe() {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
clap::ErrorKind::ValueValidation,
|
clap::ErrorKind::ValueValidation,
|
||||||
Opt::from_iter_safe(&["test", "NOPE"]).err().unwrap().kind,
|
Opt::from_iter_safe(&["test", "NOPE"]).err().unwrap().kind
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,7 +231,7 @@ fn test_custom_bool() {
|
||||||
tribool: None,
|
tribool: None,
|
||||||
bitset: vec![],
|
bitset: vec![],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dfalse"]),
|
Opt::from_iter(&["test", "-dfalse"])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Opt {
|
Opt {
|
||||||
|
@ -240,7 +240,7 @@ fn test_custom_bool() {
|
||||||
tribool: None,
|
tribool: None,
|
||||||
bitset: vec![],
|
bitset: vec![],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dtrue"]),
|
Opt::from_iter(&["test", "-dtrue"])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Opt {
|
Opt {
|
||||||
|
@ -249,7 +249,7 @@ fn test_custom_bool() {
|
||||||
tribool: None,
|
tribool: None,
|
||||||
bitset: vec![],
|
bitset: vec![],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dtrue", "-vfalse"]),
|
Opt::from_iter(&["test", "-dtrue", "-vfalse"])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Opt {
|
Opt {
|
||||||
|
@ -258,7 +258,7 @@ fn test_custom_bool() {
|
||||||
tribool: None,
|
tribool: None,
|
||||||
bitset: vec![],
|
bitset: vec![],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dtrue", "-vtrue"]),
|
Opt::from_iter(&["test", "-dtrue", "-vtrue"])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Opt {
|
Opt {
|
||||||
|
@ -267,7 +267,7 @@ fn test_custom_bool() {
|
||||||
tribool: Some(false),
|
tribool: Some(false),
|
||||||
bitset: vec![],
|
bitset: vec![],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dtrue", "-tfalse"]),
|
Opt::from_iter(&["test", "-dtrue", "-tfalse"])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Opt {
|
Opt {
|
||||||
|
@ -276,7 +276,7 @@ fn test_custom_bool() {
|
||||||
tribool: Some(true),
|
tribool: Some(true),
|
||||||
bitset: vec![],
|
bitset: vec![],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dtrue", "-ttrue"]),
|
Opt::from_iter(&["test", "-dtrue", "-ttrue"])
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Opt {
|
Opt {
|
||||||
|
@ -285,6 +285,6 @@ fn test_custom_bool() {
|
||||||
tribool: None,
|
tribool: None,
|
||||||
bitset: vec![false, true, false, false],
|
bitset: vec![false, true, false, false],
|
||||||
},
|
},
|
||||||
Opt::from_iter(&["test", "-dtrue", "-bfalse", "-btrue", "-bfalse", "-bfalse"]),
|
Opt::from_iter(&["test", "-dtrue", "-bfalse", "-btrue", "-bfalse", "-bfalse"])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue