Trait clap::FromArgMatches[][src]

pub trait FromArgMatches: Sized {
    fn from_arg_matches(matches: &ArgMatches) -> Option<Self>;
fn update_from_arg_matches(&mut self, matches: &ArgMatches); }
Expand description

Converts an instance of ArgMatches to a user-defined container.

Required methods

Instantiate Self from ArgMatches, parsing the arguments as needed.

Motivation: If our application had two CLI options, --name <STRING> and the flag --debug, we may create a struct as follows:

struct Context {
    name: String,
    debug: bool
}

We then need to convert the ArgMatches that clap generated into our struct. from_arg_matches serves as the equivalent of:

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

Assign values from ArgMatches to self.

Implementations on Foreign Types

Implementors