From 5177f41a8d575535639b18ff2bf98f52acd52f15 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 10 Feb 2018 17:08:04 +0100 Subject: [PATCH 1/2] Add the `from` method to parse from any Iterator --- src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0dd573cb..5f73cdd2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -346,6 +346,8 @@ extern crate structopt_derive; #[doc(hidden)] pub use structopt_derive::*; +use std::ffi::OsString; + /// Re-export of clap pub mod clap { pub use _clap::*; @@ -365,4 +367,15 @@ pub trait StructOpt { fn from_args() -> Self where Self: Sized { Self::from_clap(&Self::clap().get_matches()) } + + /// Gets the struct from any iterator such as a `Vec` of your making. + /// Print the error message and quit the program in case of failure. + fn from_any(iter: I) -> Self + where + Self: Sized, + I: IntoIterator, + I::Item: Into + Clone + { + Self::from_clap(&Self::clap().get_matches_from(iter)) + } } From 65cebb65adce8855949d77e12e4f010395e55ee4 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 10 Feb 2018 19:22:53 +0100 Subject: [PATCH 2/2] Add informations about `StructOpt::from_any` method to the changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d24deb6a..763966f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ You have to change `foo_raw = "bar", baz_raw = "foo"` by `raw(foo = "bar", baz = * Add `parse(from_occurrences)` parser by [@SergioBenitez](https://github.com/SergioBenitez) * Support 1-uple enum variant as subcommand by [@TeXitoi](https://github.com/TeXitoi) * structopt-derive crate is now an implementation detail, structopt reexport the custom derive macro by [@TeXitoi](https://github.com/TeXitoi) +* Add the `StructOpt::from_any` method by [@Kerollmops](https://github.com/Kerollmops) ## Documentation