Module crosvm_direct::crosvm::argument
source · [−]Expand description
Handles argument parsing.
Example
let arguments = &[
Argument::positional("FILES", "files to operate on"),
Argument::short_value('p', "program", "PROGRAM", "Program to apply to each file"),
Argument::short_value('c', "cpus", "N", "Number of CPUs to use. (default: 1)"),
Argument::flag("unmount", "Unmount the root"),
Argument::short_flag('h', "help", "Print help message."),
];
let match_res = set_arguments(args, arguments, |name, value| {
match name {
"" => println!("positional arg! {}", value.unwrap()),
"program" => println!("gonna use program {}", value.unwrap()),
"cpus" => {
let v: u32 = value.unwrap().parse().map_err(|_| {
Error::InvalidValue {
value: value.unwrap().to_owned(),
expected: String::from("this value for `cpus` needs to be integer"),
}
})?;
}
"unmount" => println!("gonna unmount"),
"help" => return Err(Error::PrintHelp),
_ => unreachable!(),
}
unreachable!();
});
match match_res {
Ok(_) => println!("running with settings"),
Err(Error::PrintHelp) => print_help("best_program", "FILES", arguments),
Err(e) => println!("{}", e),
}
Structs
Information about an argument expected from the command line.
Enums
An error with argument parsing.
Constants
Functions
Get the number of columns on a display, with a reasonable default.
Obtain the leading part of the help message. The output is later processed to reflow. Depending on how short this, newline is used.
Parse a string of delimiter-separated key-value options. This is intended to simplify parsing of command-line options that take a bunch of parameters encoded into the argument, e.g. for setting up an emulated hardware device. Returns an Iterator of KeyValuePair, which provides convenience functions to parse numeric values and performs appropriate error handling.
Prints command line usage information to stdout.
Poor man’s reflowing function for string. This function will unsplit the lines, an empty line splits a paragraph.
Parses the given args
against the list of know arguments arg_list
and calls f
with each
present argument and value if required.
Type Definitions
Result of a argument parsing.