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§

source

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

source

fn run(&self, _ctx: &mut Ctx) -> Result<()>

source

fn next_subcmd<'a>( &self, _matches: &'a ArgMatches ) -> Option<(Box<dyn CliCommand>, &'a ArgMatches)>

Implementations§

source§

impl dyn CliCommand + 'static

source

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 calls traverse_exec on 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.

source

pub fn traverse_update_ctx( &self, matches: &ArgMatches, ctx: &mut Ctx ) -> Result<()>

Implementors§