App

Struct App 

Source
pub struct App { /* private fields */ }
Expand description

Command line application

Implementations§

Source§

impl App

Source

pub fn new<T: Into<String>>(help: T, version: T) -> App

Create a new command line application.

Examples found in repository?
examples/ecla.rs (line 36)
35fn main() {
36    let app = App::new(HELP, VERSION);
37
38    if let Some(_) = app.get_command("command") {
39        command();
40    } else if let Some(command) = app.get_command("flag") {
41        let flag = command.get_flag(&["-f", "--force"]);
42        if flag.is_some() {
43            command_with_flag(flag.unwrap().get_value());
44        } else {
45            command_with_no_flag();
46        }
47    } else if let Some(command) = app.get_command("value") {
48        command_with_value(command.get_value());
49    } else {
50        app.show_unknown_or_help();
51    }
52}
Source

pub fn get_command(&self, name: &str) -> Option<Command>

Get sub command

Examples found in repository?
examples/ecla.rs (line 38)
35fn main() {
36    let app = App::new(HELP, VERSION);
37
38    if let Some(_) = app.get_command("command") {
39        command();
40    } else if let Some(command) = app.get_command("flag") {
41        let flag = command.get_flag(&["-f", "--force"]);
42        if flag.is_some() {
43            command_with_flag(flag.unwrap().get_value());
44        } else {
45            command_with_no_flag();
46        }
47    } else if let Some(command) = app.get_command("value") {
48        command_with_value(command.get_value());
49    } else {
50        app.show_unknown_or_help();
51    }
52}
Source

pub fn has_flag(&self) -> bool

Check arguments if has flags

Source

pub fn show_unknown_or_help(&self)

If you can not find any supported sub commands or flags, you can use this to tell user something is wrong.

Examples found in repository?
examples/ecla.rs (line 50)
35fn main() {
36    let app = App::new(HELP, VERSION);
37
38    if let Some(_) = app.get_command("command") {
39        command();
40    } else if let Some(command) = app.get_command("flag") {
41        let flag = command.get_flag(&["-f", "--force"]);
42        if flag.is_some() {
43            command_with_flag(flag.unwrap().get_value());
44        } else {
45            command_with_no_flag();
46        }
47    } else if let Some(command) = app.get_command("value") {
48        command_with_value(command.get_value());
49    } else {
50        app.show_unknown_or_help();
51    }
52}
Source

pub fn has_command(&self) -> bool

Check arguments if has sub command

Source

pub fn get_flag<T: AsRef<str>>(&self, names: &[T]) -> Option<Flag>

Get flag

Source

pub fn show_command_unknown(&self)

Tell user is entering an unknown sub command

Source

pub fn show_help(&self)

Print help message

Source

pub fn show_version(&self)

Print version

Trait Implementations§

Source§

impl Debug for App

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for App

§

impl RefUnwindSafe for App

§

impl Send for App

§

impl Sync for App

§

impl Unpin for App

§

impl UnwindSafe for App

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.