Struct App

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

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

Implementations§

Source§

impl App

Source

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.

Source

pub fn name(self, name: &str) -> Self

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

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

pub fn version(self, version: &str) -> Self

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

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

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

pub fn run_custom(&self, args: Vec<String>) -> Result<Option<String>, String>

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§

Source§

impl Default for App

Source§

fn default() -> Self

Returns the “default value” for a type. 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.