[][src]Struct commander_core::Cli

pub struct Cli {
    pub cmd: Option<Cmd>,
    pub global_raws: HashMap<String, Raw>,
    pub direct_args: Vec<Raw>,
}

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:

This example is not tested
#[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>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: From<Raw>>(&self, idx: &str, d: T) -> T[src]

Getting contents of Options. if idx dont exist, return default.

pub fn get_or_else<T: From<Raw>, F>(&self, idx: &str, f: F) -> T where
    F: FnOnce() -> T, 
[src]

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

impl Debug for Cli[src]

Auto Trait Implementations

impl Send for Cli

impl Sync for Cli

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Any for T where
    T: 'static + ?Sized
[src]