pub trait ActionCommand<T = (), E = Box<dyn Error>> {
// Required methods
fn name(&self) -> &'static str;
fn command(&self, command: Command) -> Command;
fn action(&self, matches: Vec1<&ArgMatches>) -> Result<T, E>;
}
Expand description
A type that encapsulates the Clap Command
and associated
behavior of that command when it is matched.
struct HelloWorldCommand {}
impl ActionCommand for HelloWorldCommand {
fn name(&self) -> &'static str {
"hello-world"
}
fn command(&self, command: Command) -> Command {
command
.about("Say hello to the world")
.alias("h")
}
fn action(
&self, _matches: Vec1<&ArgMatches>,
) -> Result<(), Box<dyn std::error::Error>> {
println!("Hello, world!");
Ok(())
}
}
Required Methods§
Sourcefn command(&self, command: Command) -> Command
fn command(&self, command: Command) -> Command
The Command
that describes how to match this on the command
line using Clap. command
is already constructed using
Self::name
for convenience.
Sourcefn action(&self, matches: Vec1<&ArgMatches>) -> Result<T, E>
fn action(&self, matches: Vec1<&ArgMatches>) -> Result<T, E>
The action to take when this command is matched on the command
line. CommandMap
s may be nested, and this is represented
by the matches being returned as a list of at least one element.