pub struct App { /* private fields */ }
Expand description
Holds information about the application: commands, options, name, version, etc.
Implementations
sourceimpl App
impl App
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs and returns a default App.
Initializes the name, description, and version with empty strings.
Use the create_app macro instead if you want to construct and return an app with values for the name, description, and version taken from the crate’s Cargo.toml file.
sourcepub fn desc(self, desc: &str) -> Self
pub fn desc(self, desc: &str) -> Self
Set the description of the application.
The description is displayed whenever the application help menu is displayed.
Arguments
- ‘desc’ - A string slice that holds the description of the application
Examples
Creating an app and changing its description:
use climb::*;
let my_app = create_app!()
.desc("Super cool app that does a lot of stuff");
sourcepub fn command(self, command: Command) -> Self
pub fn command(self, command: Command) -> Self
Add a command to the application
Commands give functionality to your application. They are displayed in the application help menu. You can add as many commands as you want to an application.
For more information on commands, see Command
Arguments
command
- A command struct to add to the application
Examples
Creating an application and adding a command to it:
use climb::*;
fn example_cmd_fn(_: FunctionInput, _: FunctionOptions) -> FunctionResult {
println!("my example function");
Ok(None)
}
let my_command = Command::new(
"cmd_name",
"cmd_desc",
example_cmd_fn
);
let my_app = create_app!()
.command(my_command);
sourcepub fn run(&self) -> Result<Option<String>, String>
pub fn run(&self) -> Result<Option<String>, String>
Runs the application with command line arguments
Collects the arguments from the command line, parses them, and passes them into the correct function. The arguments passed into the function are guaranteed to be correct and valid.
The result of running the command is returned by this function. If any errors
occur when parsing the command line input (command not found, wrong option name, etc.),
then this function will print a help menu and return Ok(None)
.
Examples
Creating an app, changing some of its values, and running it:
use climb::*;
let my_app = create_app!()
.version("1.2.3");
let app_result = my_app.run();