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

Application command type

Fields

name: String

Command name

description: Option<String>

Command description

usage: Option<String>

Command usage

action: Option<Action>

Command action

flags: Option<Vec<Flag>>

Action flags

alias: Option<Vec<String>>

Command alias

commands: Option<Vec<Command>>

Implementations

Create new instance of Command

Example

use seahorse::Command;

let command = Command::new("cmd");

Set description of the command

Example

use seahorse::Command;

let command = Command::new("cmd")
    .description("cli sub command");

Set usage of the command

Example

use seahorse::Command;

let command = Command::new("cmd")
    .usage("cli cmd [arg]");

Set action of the command

Example

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

let action: Action = |c: &Context| println!("{:?}", c.args);
let command = Command::new("cmd")
    .action(action);

Set flag of the command

Example

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

let command = Command::new("cmd")
    .flag(Flag::new("bool", FlagType::Bool))
    .flag(Flag::new("int", FlagType::Int));

Set alias of the command

Example

use seahorse::Command;

let command = Command::new("cmd")
    .alias("c");

Set sub command of the command

Example

use seahorse::{App, Command};

let sub_command = Command::new("world")
    .usage("cli hello world")
    .action(|_| println!("Hello world!"));

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

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

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

use seahorse::{App, Command};

let sub_command1 = Command::new("world")
    .usage("cli hello world")
    .action(|_| println!("Hello world!"));

let sub_command2 = Command::new("world")
    .usage("cli hello world")
    .action(|_| println!("Hello world!"));

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

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

Run command Call this function only from App

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.