Skip to content

Commit

Permalink
Fix #168
Browse files Browse the repository at this point in the history
  • Loading branch information
TeXitoi committed Mar 8, 2019
1 parent 2a30e71 commit 3d5f9bd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "structopt"
version = "0.2.14"
version = "0.2.15"
authors = ["Guillaume Pinot <[email protected]>", "others"]
description = "Parse command line argument by defining a struct."
documentation = "https://docs.rs/structopt"
Expand All @@ -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]
1 change: 0 additions & 1 deletion examples/doc_comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion structopt-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "structopt-derive"
version = "0.2.14"
version = "0.2.15"
authors = ["Guillaume Pinot <[email protected]>"]
description = "Parse command line argument by defining a struct, derive crate."
documentation = "https://docs.rs/structopt-derive"
Expand Down
1 change: 0 additions & 1 deletion structopt-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ fn gen_constructor(fields: &Punctuated<Field, Comma>, parent_attribute: &Attrs)
Ty::Bool => quote!(matches.is_present(#name)),
Ty::Option => quote! {
matches.#value_of(#name)
.as_ref()
.map(#parse)
},
Ty::Vec => quote! {
Expand Down
21 changes: 21 additions & 0 deletions tests/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<A>,
}

assert_eq!(Opt { a: None }, Opt::from_iter(&["test"]));
assert_eq!(Opt { a: Some(A) }, Opt::from_iter(&["test", "foo"]));
}

0 comments on commit 3d5f9bd

Please sign in to comment.