[][src]Trait clap::FromArgMatches

pub trait FromArgMatches: Sized {
    fn from_arg_matches(matches: &ArgMatches) -> Self;
}

Converts an instance of ArgMatches to a consumer defined struct.

Required methods

fn from_arg_matches(matches: &ArgMatches) -> Self

It's common to have an "application context" struct (sometimes called config) that represents all the normalized values after being processed by the CLI.

For instance, if an application we made had two CLI options, --name <STRING> and a flag --debug to distinguish "debugging mode" for our made up CLI, we may create a context struct as follows:

struct Context {
    name: String,
    debug: bool
}

And after letting clap parse the CLI, we get back and instance of ArgMatches, we may create a From implementation like so:

impl From<ArgMatches> for Context {
   fn from(m: ArgMatches) -> Self {
       Context {
           name: m.value_of("name").unwrap().to_string(),
           debug: m.is_present("debug"),
       }
   }
}
Loading content...

Implementations on Foreign Types

impl<T: FromArgMatches> FromArgMatches for Box<T>[src]

Loading content...

Implementors

Loading content...