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
sourceimpl Command
impl Command
sourcepub fn new<T: Into<String>>(name: T) -> Self
pub fn new<T: Into<String>>(name: T) -> Self
Create new instance of Command
Example
use seahorse::Command;
let command = Command::new("cmd");
sourcepub fn description<T: Into<String>>(self, description: T) -> Self
pub fn description<T: Into<String>>(self, description: T) -> Self
Set description of the command
Example
use seahorse::Command;
let command = Command::new("cmd")
.description("cli sub command");
sourcepub fn usage<T: Into<String>>(self, usage: T) -> Self
pub fn usage<T: Into<String>>(self, usage: T) -> Self
Set usage of the command
Example
use seahorse::Command;
let command = Command::new("cmd")
.usage("cli cmd [arg]");
sourcepub fn action(self, action: Action) -> Self
pub fn action(self, action: Action) -> Self
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);
sourcepub fn flag(self, flag: Flag) -> Self
pub fn flag(self, flag: Flag) -> Self
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));
sourcepub fn alias<T: Into<String>>(self, name: T) -> Self
pub fn alias<T: Into<String>>(self, name: T) -> Self
Set alias of the command
Example
use seahorse::Command;
let command = Command::new("cmd")
.alias("c");
sourcepub fn command(self, command: Command) -> Self
pub fn command(self, command: Command) -> Self
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);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Command
impl Send for Command
impl Sync for Command
impl Unpin for Command
impl UnwindSafe for Command
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more