diff --git a/src/cli_util.rs b/src/cli_util.rs index 01d68f806..b087b5bb8 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -356,6 +356,7 @@ pub struct CommandHelper { app: Command, cwd: PathBuf, string_args: Vec, + matches: ArgMatches, global_args: GlobalArgs, settings: UserSettings, layered_configs: LayeredConfigs, @@ -369,6 +370,7 @@ impl CommandHelper { app: Command, cwd: PathBuf, string_args: Vec, + matches: ArgMatches, global_args: GlobalArgs, settings: UserSettings, layered_configs: LayeredConfigs, @@ -379,6 +381,7 @@ impl CommandHelper { app, cwd, string_args, + matches, global_args, settings, layered_configs, @@ -399,6 +402,10 @@ impl CommandHelper { &self.string_args } + pub fn matches(&self) -> &ArgMatches { + &self.matches + } + pub fn global_args(&self) -> &GlobalArgs { &self.global_args } @@ -2274,8 +2281,7 @@ pub struct CliRunner { process_global_args_fns: Vec, } -type CliDispatchFn = - Box Result<(), CommandError>>; +type CliDispatchFn = Box Result<(), CommandError>>; type ProcessGlobalArgsFn = Box Result<(), CommandError>>; @@ -2314,11 +2320,11 @@ impl CliRunner { { let old_dispatch_fn = self.dispatch_fn; let new_dispatch_fn = - move |ui: &mut Ui, command_helper: &CommandHelper, matches: &ArgMatches| { - match C::from_arg_matches(matches) { - Ok(command) => custom_dispatch_fn(ui, command_helper, command), - Err(_) => old_dispatch_fn(ui, command_helper, matches), - } + move |ui: &mut Ui, command_helper: &CommandHelper| match C::from_arg_matches( + command_helper.matches(), + ) { + Ok(command) => custom_dispatch_fn(ui, command_helper, command), + Err(_) => old_dispatch_fn(ui, command_helper), }; self.app = C::augment_subcommands(self.app); self.dispatch_fn = Box::new(new_dispatch_fn); @@ -2374,13 +2380,14 @@ impl CliRunner { self.app, cwd, string_args, + matches, args.global_args, settings, layered_configs, maybe_workspace_loader, self.store_factories.unwrap_or_default(), ); - (self.dispatch_fn)(ui, &command_helper, &matches) + (self.dispatch_fn)(ui, &command_helper) } #[must_use] diff --git a/src/commands/mod.rs b/src/commands/mod.rs index a2d7d0b8d..91c598de0 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -26,7 +26,7 @@ use std::sync::Arc; use std::{fs, io}; use clap::builder::NonEmptyStringValueParser; -use clap::{ArgGroup, ArgMatches, Command, CommandFactory, FromArgMatches, Subcommand}; +use clap::{ArgGroup, Command, CommandFactory, FromArgMatches, Subcommand}; use indexmap::{IndexMap, IndexSet}; use itertools::Itertools; use jujutsu_lib::backend::{CommitId, ObjectId, TreeValue}; @@ -3476,12 +3476,9 @@ pub fn default_app() -> Command { Commands::augment_subcommands(Args::command()) } -pub fn run_command( - ui: &mut Ui, - command_helper: &CommandHelper, - matches: &ArgMatches, -) -> Result<(), CommandError> { - let derived_subcommands: Commands = Commands::from_arg_matches(matches).unwrap(); +pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), CommandError> { + let derived_subcommands: Commands = + Commands::from_arg_matches(command_helper.matches()).unwrap(); match &derived_subcommands { Commands::Version(sub_args) => cmd_version(ui, command_helper, sub_args), Commands::Init(sub_args) => cmd_init(ui, command_helper, sub_args),