pub trait CliCommand {
// Provided methods
fn update_ctx(&self, _matches: &ArgMatches, _ctx: &mut Ctx) -> Result<()> { ... }
fn run(&self, _ctx: &mut Ctx) -> Result<()> { ... }
fn next_subcmd<'a>(
&self,
_matches: &'a ArgMatches,
) -> Option<(Box<dyn CliCommand>, &'a ArgMatches)> { ... }
}Provided Methods§
Sourcefn update_ctx(&self, _matches: &ArgMatches, _ctx: &mut Ctx) -> Result<()>
fn update_ctx(&self, _matches: &ArgMatches, _ctx: &mut Ctx) -> Result<()>
Care should be taken to keep CliCommand::update_ctx pure with no external effects such as I/O. This allows the CLI to be fully tested without any assumptions of the testing environment
fn run(&self, _ctx: &mut Ctx) -> Result<()>
fn next_subcmd<'a>( &self, _matches: &'a ArgMatches, ) -> Option<(Box<dyn CliCommand>, &'a ArgMatches)>
Implementations§
Source§impl dyn CliCommand + 'static
impl dyn CliCommand + 'static
Sourcepub fn traverse_exec(&self, matches: &ArgMatches, ctx: &mut Ctx) -> Result<()>
pub fn traverse_exec(&self, matches: &ArgMatches, ctx: &mut Ctx) -> Result<()>
Performs three steps:
- calls
self.update_ctx() - calls
self.run() - Gets the next subcommand (if any) by calling
self.next_subcmd()and callstraverse_execon that subcommand.
This walks down the entire used subcommand hierarchy ensuring the update_ctx was called
prior to run and that any deeper subcommands were executed.