[−][src]Struct commander_rust::Cli
Something like Cmd
.
But unfortunately, you will use it frequently.
commander_rust
will generate a instance of Application
according your code. It happens in compile-time.
commander_rust
will generate a instance of Cli
according user's input. It happens in run-time.
What' the difference?
Content in Application
will be replaced by something concrete through user's input.
For example, If your code is like this:
#[option(-r, --recursive [dir...], "recursively")] #[command(rmdir <dir> [otherDirs...], "remove files and directories")] fn rmdir(dir: i32, other_dirs: Option<Vec<bool>>, cli: Cli) { let r: bool = cli.get("recursive").into(); }
Let's see. The last argument of function is Cli
type(you can miss it).
So when we want to do something if --recursive
is offered by user, how can we?
You just need to code like let r: ? = cli.get("recursive").into()
,
then you can get contents of recursive
options if user has inputted it.
That's why Cli
will be used frequently.
Fields
cmd: Option<Cmd>
global_raws: HashMap<String, Raw, RandomState>
direct_args: Vec<Raw>
Methods
impl Cli
[src]
pub fn get(&self, idx: &str) -> Raw
[src]
Get the content of Options
.
Options
has two types, one is private, the other is global. Of course they are same.
Private means they belong to the command.
Global means they belong to the global.
Private is more weight than global.
pub fn get_or<T>(&self, idx: &str, d: T) -> T where
T: From<Raw>,
[src]
T: From<Raw>,
Getting contents of Options
. if idx
dont exist, return default
.
pub fn get_or_else<T, F>(&self, idx: &str, f: F) -> T where
F: FnOnce() -> T,
T: From<Raw>,
[src]
F: FnOnce() -> T,
T: From<Raw>,
Get contents of Options
. if idx
dont exist, call f.
f should return a value of type T.
pub fn has(&self, idx: &str) -> bool
[src]
Check user input a option or not.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,