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 - A BTreeMap<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 the Arg 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 the Arg 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;
}

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

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.