pub struct App {
    pub name: String,
    pub author: Option<String>,
    pub description: Option<String>,
    pub usage: Option<String>,
    pub version: Option<String>,
    pub commands: Option<Vec<Command>>,
    pub action: Option<Action>,
    pub flags: Option<Vec<Flag>>,
}
Expand description

Multiple action application entry point

Fields

name: String

Application name

author: Option<String>

Application author

description: Option<String>

Application description

usage: Option<String>

Application usage

version: Option<String>

Application version

commands: Option<Vec<Command>>

Application commands

action: Option<Action>

Application action

flags: Option<Vec<Flag>>

Application flags

Implementations

Create new instance of App

Example

use seahorse::App;

let app = App::new("cli");

Set author of the app

Example

use seahorse::App;

let app = App::new("cli")
    .author(env!("CARGO_PKG_AUTHORS"));

Set description of the app

Example

use seahorse::App;

let app = App::new("cli")
    .description(env!("CARGO_PKG_DESCRIPTION"));

Set usage of the app

Example

use seahorse::App;

let app = App::new("cli");
app.usage("cli [command] [arg]");

Set version of the app

Example

use seahorse::App;

let app = App::new("cli");
app.version(env!("CARGO_PKG_VERSION"));

Set command of the app

Example

use seahorse::{App, Command};

let command = Command::new("hello")
    .usage("cli hello [arg]")
    .action(|c| println!("{:?}", c.args));

let app = App::new("cli")
    .command(command);
Panics

You cannot set a command named as same as registered ones.

use seahorse::{App, Command};

let command1 = Command::new("hello")
    .usage("cli hello [arg]")
    .action(|c| println!("{:?}", c.args));

let command2 = Command::new("hello")
    .usage("cli hello [arg]")
    .action(|c| println!("{:?}", c.args));

let app = App::new("cli")
    .command(command1)
    .command(command2);

Set action of the app

Example

use seahorse::{Action, App, Context};

let action: Action = |c: &Context| println!("{:?}", c.args);
let app = App::new("cli")
    .action(action);

Set flag of the app

Example

use seahorse::{App, Flag, FlagType};

let app = App::new("cli")
    .flag(Flag::new("bool", FlagType::Bool))
    .flag(Flag::new("int", FlagType::Int));

Run app

Example

use std::env;
use seahorse::App;

let args: Vec<String> = env::args().collect();
let app = App::new("cli");
app.run(args);

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.