Function get_one

Source
pub fn get_one<'a, T: Any + Clone + Send + Sync + 'static>(
    matches: &[&'a ArgMatches],
    id: &str,
) -> Option<&'a T>
Expand description

Helper function for dealing with chains of ArgMatches while working in ActionCommand::action to find arguments which may have been specified anywhere in the subcommand tree.

// my-program --my-arg alpha my-subcommand --my-arg beta
let arg = get_one::<String>(&matches, "my-arg");
assert_eq!("beta", arg.unwrap());

This function respects the provenance (clap::parser::ValueSource) of arguments. For example, a default or environment-sourced value will never override a value specified explicitly on the command line.