Command

Struct Command 

Source
pub struct Command<'a> { /* private fields */ }
Expand description

Command structure, which describes a command and its action.

Implementations§

Source§

impl<'a> Command<'a>

Source

pub fn new<S: Into<String>>(n: S) -> Self

Create a command

Source

pub fn new_with_alias<S: Into<String>>(n: S, s: S) -> Self

Source

pub fn get_name(&self) -> &str

Get the name of this command.

Source

pub fn get_alias(&self) -> &Option<String>

Get the alias name of this command.

Source

pub fn action(self, action: fn(&App<'_>, &[&str]) -> XcliResult) -> Self

Set a CmdAction to this command.

Source

pub fn about<S: Into<&'a str>>(self, about: S) -> Self

Set a description to this command.

Source

pub fn usage<S: Into<&'a str>>(self, about: S) -> Self

Set the usage to this command.

Source

pub fn get_subcommands(&self) -> &[Command<'a>]

Get all subcommands of this command

Source

pub fn subcommand(self, subcmd: Command<'a>) -> Self

Add a subcommand to this command

Source

pub fn subcommands<I>(self, subcmds: I) -> Self
where I: IntoIterator<Item = Command<'a>>,

Add more than one subcommand to this command, the given subcmds implements IntoIterator

Source

pub fn show_command_usage(&self)

show usage message for command.

Source

pub fn show_command_help(&self)

show help message for command.

Source

pub fn show_subcommand_help(&self)

show help message for command and its subs

Source

pub fn locate_subcommand(&self, args: &[&str]) -> Option<&Command<'_>>

locate the sub command by the args given

Source

pub fn run_sub(&self, app: &App<'_>, args: &[&str]) -> XcliResult

run sub commands

show error message when action not found but with extra args

show help messages when action not found for the sub command

execute sub command when action found

Source

pub fn for_each<F>(&self, path: &str, f: &mut F)
where F: FnMut(&Self, &str),

Trait Implementations§

Source§

impl<'a> Default for Command<'a>

Source§

fn default() -> Command<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Command<'a>

§

impl<'a> RefUnwindSafe for Command<'a>

§

impl<'a> Send for Command<'a>

§

impl<'a> Sync for Command<'a>

§

impl<'a> Unpin for Command<'a>

§

impl<'a> UnwindSafe for Command<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.