diff --git a/src/cli.rs b/src/cli.rs index 29e6491..17b8cd4 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -27,6 +27,7 @@ pub struct CliApp, make_ctx: Box Result + Send + Sync>, root_handler: ParentHandler, + mut_cmd: Option clap::Command + Send + Sync>>, } impl CliApp @@ -39,8 +40,16 @@ impl _phantom: PhantomData::new(), make_ctx: Box::new(make_ctx), root_handler, + mut_cmd: None, } } + pub fn mutate_command( + mut self, + f: impl FnOnce(clap::Command) -> clap::Command + Send + Sync + 'static, + ) -> Self { + self.mut_cmd = Some(Box::new(f)); + self + } pub fn run(self, args: impl IntoIterator) -> Result<(), RpcError> { let mut cmd = Config::command(); for (name, handler) in &self.root_handler.subcommands.1 { @@ -48,6 +57,9 @@ impl cmd = cmd.subcommand(cli.cli_command().name(name)); } } + if let Some(f) = self.mut_cmd { + cmd = f(cmd); + } let matches = cmd.get_matches_from(args); let config = Config::from_arg_matches(&matches)?; let ctx = (self.make_ctx)(config)?;