pub struct App { /* private fields */ }Expand description
Command line application
Implementations§
Source§impl App
impl App
Sourcepub fn new<T: Into<String>>(help: T, version: T) -> App
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}Sourcepub fn get_command(&self, name: &str) -> Option<Command>
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}Sourcepub fn show_unknown_or_help(&self)
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}Sourcepub fn has_command(&self) -> bool
pub fn has_command(&self) -> bool
Check arguments if has sub command
Sourcepub fn show_command_unknown(&self)
pub fn show_command_unknown(&self)
Tell user is entering an unknown sub command
Sourcepub fn show_version(&self)
pub fn show_version(&self)
Print version
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more