#[option]Expand description
Declares a command option.
Any option declaration must contains the name of the argument for example:
#[option(name)].
By default any function argument is considered a command option,
Use this attribute to provide additional information like arg, alias,
description or min, max, default and values arguments.
§Options
name: Name of the option, by default is the function argument name.arg: Name of the option argument, by default is the function argument name.alias: Alias of the function argument.description: Description of the option.min: Min number of values the option takes.max: Max number of values the option takes.default: Default value(s) of the option.values: Valid values of the option.hidden: If the option is hidden for the help.multiple: If the option allow multiple declarations.flag: If the option is a bool flag, by default istrueerror: Error show when the value is invalid.require_assign: If the option requires to use=to assign the value, by default false,global: If the option is global, by default false.from_global: If the option is declared as global in a parent, by default false.
Function arguments can be declared as the following types:
- Any type that implement
FromStr. Vec<T>whereTimplementsFromStr.&[T]slices whereTimplementsFromStr.Option<T>whereTimplementsFromStr.
§Example:
ⓘ
use clapi::macros::*;
#[command]
#[option(repeat, alias="r", default=1)]
#[option(upper_case, alias="u", description="Display the message in uppercase")]
fn main(repeat: u32, upper_case: bool){
for _ in 0..repeat {
if upper_case {
println!("HELLO WORLD");
} else {
println!("hello world");
}
}
}