Struct parg::CliArguments [−][src]
pub struct CliArguments<'a> { /* fields omitted */ }
Expand description
Argument Engine looking for all Arg
.
Implementations
Construct a new CliArguments.
Arguments
named_args
- ABTreeMap<String, &Arg>
of the arguments
Example
Can be use directly
let a = Arg::with_value("config", Type::ReadAsString, true); let b = Arg::with_value("thread", Type::ReadAsU8, false); let c = Arg::without_value("verbose", false); let mut tree: BTreeMap<String, &Arg> = BTreeMap::new(); tree.insert(a.get_name(), &a); tree.insert(b.get_name(), &b); tree.insert(c.get_name(), &c); // Create the cli let cli: CliArguments = CliArguments::new(tree);
Or using create_cli_argument!
let a = Arg::with_value("config", Type::ReadAsString, true); let b = Arg::with_value("thread", Type::ReadAsU8, false); let c = Arg::without_value("verbose", false); // Create the cli let cli: CliArguments = create_cli_arguments!(&a, &b, &c);
Check if an Arg
exists.
Arguments
arg_name
- The name of theArg
to check.
Returns
Return true
if the Arg
exists, false
otherwise.
Example
let a = Arg::with_value("config", Type::ReadAsString, true); let b = Arg::with_value("thread", Type::ReadAsU8, false); let c = Arg::without_value("verbose", false); // Create the cli let cli: CliArguments = create_cli_arguments!(&a, &b, &c); // parse args and get return status let return_status = cli.parse(); if let Err(msg) = return_status { eprintln!("{}", msg); return; } // get the value as a String let verbose = cli.exists("verbose"); if verbose { // do stuff }
Generate a text to explain usage
Get the value of the arg_name
argument.
Arguments
arg_name
- The name of theArg
to get the value of.
Returns
Return a value: T
, T being the requested type.
Example
let a = Arg::with_value("config", Type::ReadAsString, true); let b = Arg::with_value("thread", Type::ReadAsU8, false); let c = Arg::without_value("verbose", false); // Create the cli let cli: CliArguments = create_cli_arguments!(&a, &b, &c); // parse args and get return status let return_status = cli.parse(); if let Err(msg) = return_status { eprintln!("{}", msg); return; } // get the value as a String let config: String = cli.get_value("config"); // if command is ... --config "a config" ... // print: config = a config println!("config = {}", config);
Parse the command line arguments.
Returns
Return a Result<(), String>
, String being the error message if any.
Example
let a = Arg::with_value("config", Type::ReadAsString, true); let b = Arg::with_value("thread", Type::ReadAsU8, false); let c = Arg::without_value("verbose", false); // Create the cli let cli: CliArguments = create_cli_arguments!(&a, &b, &c); // parse args and get return status let return_status = cli.parse(); if let Err(msg) = return_status { eprintln!("{}", msg); return; }
pub fn parse_subset<T>(&self, args: T) -> Result<(), String> where
T: Iterator<Item = String>,
[src]Sets the cli name and description.
Arguments
app_name
- The name of the cli app.description
- The description of the cli app.
Example
let a = Arg::with_value("config", Type::ReadAsString, true); let b = Arg::with_value("thread", Type::ReadAsU8, false); let c = Arg::without_value("verbose", false); // Create the cli let cli: CliArguments = create_cli_arguments!(&a, &b, &c); cli.set_info("my_app", "The app description");
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for CliArguments<'a>
impl<'a> !Send for CliArguments<'a>
impl<'a> !Sync for CliArguments<'a>
impl<'a> Unpin for CliArguments<'a>
impl<'a> !UnwindSafe for CliArguments<'a>