Struct climb::App

source · []
pub struct App { /* private fields */ }
Expand description

Holds information about the application: commands, options, name, version, etc.

Implementations

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.

Set the name of the application.

The name is displayed whenever the application help menu is displayed.

Arguments
  • name - A string slice that holds the name of the application
Examples

Creating an app and change its name:

use climb::*;

let my_app = create_app!().name("new_name");

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");

Set the version of the application.

The version is displayed whenever the --version option is passed.

Arguments
  • desc - A string slice that holds the version of the application
Examples

Creating an app and changing its version:

use climb::*;

let my_app = create_app!().version("1.0.4");

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);

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();

Runs the application with custom arguments.

Behaves exactly the same as run, but allows for inputting custom arguments instead of gathering them from the command line.

Arguments
  • args - A vector of strings representing the arguments to be parsed

Trait Implementations

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.