Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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<I>(iter: I) -> Self
where
Self: Sized,
I: IntoIterator,
I::Item: Into<OsString> + Clone
{
Self::from_clap(&Self::clap().get_matches_from(iter))
}
}