Trait puff_rs::program::RunnableCommand
source · pub trait RunnableCommand: 'static {
fn cli_parser(&self) -> Command;
fn make_runnable(
&mut self,
args: &ArgMatches,
dispatcher: PuffContext
) -> Result<Runnable>;
}Expand description
A Puff command that integrates with the CLI.
Specify new custom commands with puff by implementing this interface.
Example:
use std::process::ExitCode;
use puff_rs::program::{clap:: {ArgMatches, Command}, Runnable, RunnableCommand};
use puff_rs::context::PuffContext;
struct MyCommand;
impl RunnableCommand for MyCommand {
fn cli_parser(&self) -> Command {
Command::new("my_custom_command")
}
fn make_runnable(&mut self, _args: &ArgMatches, context: PuffContext) -> puff_rs::errors::Result<Runnable> {
// Setup code.
Ok(Runnable::new(async {
// Do something in async context.
Ok(ExitCode::SUCCESS)
}))
}
}Required Methods
sourcefn cli_parser(&self) -> Command
fn cli_parser(&self) -> Command
The clap::Command that specifies the arguments and meta information.
sourcefn make_runnable(
&mut self,
args: &ArgMatches,
dispatcher: PuffContext
) -> Result<Runnable>
fn make_runnable(
&mut self,
args: &ArgMatches,
dispatcher: PuffContext
) -> Result<Runnable>
Converts parsed matches from the command line into a Runnable future.