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 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)) + } }