diff --git a/CHANGELOG.md b/CHANGELOG.md index 0613886d..4e22ce4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# v0.2.15 (2018-03-08) + +* Fix [#168](https://github.com/TeXitoi/structopt/issues/168) by [@TeXitoi](https://github.com/TeXitoi) + # v0.2.14 (2018-12-10) * Introduce smarter parsing of doc comments by [@0ndorio](https://github.com/0ndorio) diff --git a/Cargo.toml b/Cargo.toml index cdf83f13..a5993c0e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "structopt" -version = "0.2.14" +version = "0.2.15" authors = ["Guillaume Pinot ", "others"] description = "Parse command line argument by defining a struct." documentation = "https://docs.rs/structopt" @@ -27,6 +27,6 @@ travis-ci = { repository = "TeXitoi/structopt" } [dependencies] clap = { version = "2.21", default-features = false } -structopt-derive = { path = "structopt-derive", version = "0.2.14" } +structopt-derive = { path = "structopt-derive", version = "0.2.15" } [workspace] diff --git a/examples/doc_comments.rs b/examples/doc_comments.rs index 32028dff..ddadd76f 100644 --- a/examples/doc_comments.rs +++ b/examples/doc_comments.rs @@ -9,7 +9,6 @@ #[macro_use] extern crate structopt; -use std::path::PathBuf; use structopt::StructOpt; /// A basic example for the usage of doc comments as replacement diff --git a/structopt-derive/Cargo.toml b/structopt-derive/Cargo.toml index 7a2e06fb..ed8d1e1c 100644 --- a/structopt-derive/Cargo.toml +++ b/structopt-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "structopt-derive" -version = "0.2.14" +version = "0.2.15" 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/lib.rs b/structopt-derive/src/lib.rs index f0edce65..98b29362 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -220,7 +220,6 @@ fn gen_constructor(fields: &Punctuated, parent_attribute: &Attrs) Ty::Bool => quote!(matches.is_present(#name)), Ty::Option => quote! { matches.#value_of(#name) - .as_ref() .map(#parse) }, Ty::Vec => quote! { diff --git a/tests/options.rs b/tests/options.rs index 447f1cda..072595d5 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -130,3 +130,24 @@ fn empy_default_value() { Opt::from_iter(&["test", "-afoo"]) ); } + +#[test] +fn option_from_str() { + #[derive(Debug, PartialEq)] + struct A; + + impl<'a> From<&'a str> for A { + fn from(_: &str) -> A { + A + } + } + + #[derive(Debug, StructOpt, PartialEq)] + struct Opt { + #[structopt(parse(from_str))] + a: Option, + } + + assert_eq!(Opt { a: None }, Opt::from_iter(&["test"])); + assert_eq!(Opt { a: Some(A) }, Opt::from_iter(&["test", "foo"])); +}