From 12acd6121a7c2524539fe83dda07b53d0648c56d Mon Sep 17 00:00:00 2001 From: Guillaume Pinot Date: Mon, 12 Feb 2018 23:46:15 +0100 Subject: [PATCH] Fix #66 --- CHANGELOG.md | 6 +++++- Cargo.toml | 4 ++-- structopt-derive/Cargo.toml | 2 +- structopt-derive/src/attrs.rs | 4 ++-- tests/options.rs | 11 +++++++++++ 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36cd2070..38386f3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ +# v0.2.2 (2018-02-12) + +* Fix [#66](https://github.com/TeXitoi/structopt/issues/66) by [@TeXitoi](https://github.com/TeXitoi) + # v0.2.1 (2018-02-11) * Fix a bug around enum tuple and the about message in the global help by [@TeXitoi](https://github.com/TeXitoi) -* Fix #65 by [@TeXitoi](https://github.com/TeXitoi) +* Fix [#65](https://github.com/TeXitoi/structopt/issues/65) by [@TeXitoi](https://github.com/TeXitoi) # v0.2.0 (2018-02-10) diff --git a/Cargo.toml b/Cargo.toml index 60d00d2d..453ce2c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "structopt" -version = "0.2.1" +version = "0.2.2" authors = ["Guillaume Pinot "] description = "Parse command line argument by defining a struct." documentation = "https://docs.rs/structopt" @@ -18,6 +18,6 @@ travis-ci = { repository = "TeXitoi/structopt" } [dependencies] clap = { version = "2.20", default-features = false } -structopt-derive = { path = "structopt-derive", version = "0.2.1" } +structopt-derive = { path = "structopt-derive", version = "0.2.2" } [workspace] diff --git a/structopt-derive/Cargo.toml b/structopt-derive/Cargo.toml index e50cd8bf..e1e0e9c8 100644 --- a/structopt-derive/Cargo.toml +++ b/structopt-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "structopt-derive" -version = "0.2.1" +version = "0.2.2" authors = ["Guillaume Pinot "] description = "Parse command line argument by defining a struct, derive crate." documentation = "https://docs.rs/structopt-derive" diff --git a/structopt-derive/src/attrs.rs b/structopt-derive/src/attrs.rs index 8177a516..16050c9d 100644 --- a/structopt-derive/src/attrs.rs +++ b/structopt-derive/src/attrs.rs @@ -56,11 +56,11 @@ impl Attrs { } fn push_str_method(&mut self, name: &str, arg: &str) { match (name, arg) { - (name, "") => { + ("about", "") | ("version", "") | ("author", "") => { let methods = mem::replace(&mut self.methods, vec![]); self.methods = methods .into_iter() - .filter(|m| m.name == name) + .filter(|m| m.name != name) .collect(); } ("name", new_name) => self.name = new_name.into(), diff --git a/tests/options.rs b/tests/options.rs index 166961ad..04ee9cf6 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -83,3 +83,14 @@ fn options() { assert_eq!(Opt { arg: vec![24, 42] }, Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a24", "--arg", "42"]))); } + +#[test] +fn empy_default_value() { + #[derive(StructOpt, PartialEq, Debug)] + struct Opt { + #[structopt(short = "a", default_value = "")] + arg: String, + } + assert_eq!(Opt { arg: "".into() }, Opt::from_iter(&["test"])); + assert_eq!(Opt { arg: "foo".into() }, Opt::from_iter(&["test", "-afoo"])); +}