diff --git a/cli/src/commands/file/chmod.rs b/cli/src/commands/file/chmod.rs index 8b97da4e57..05917df505 100644 --- a/cli/src/commands/file/chmod.rs +++ b/cli/src/commands/file/chmod.rs @@ -50,23 +50,6 @@ pub(crate) struct FileChmodArgs { paths: Vec, } -#[instrument(skip_all)] -pub(crate) fn deprecated_cmd_chmod( - ui: &mut Ui, - command: &CommandHelper, - args: &FileChmodArgs, -) -> Result<(), CommandError> { - writeln!( - ui.warning_default(), - "`jj chmod` is deprecated; use `jj file chmod` instead, which is equivalent" - )?; - writeln!( - ui.warning_default(), - "`jj chmod` will be removed in a future version, and this will be a hard error" - )?; - cmd_file_chmod(ui, command, args) -} - #[instrument(skip_all)] pub(crate) fn cmd_file_chmod( ui: &mut Ui, diff --git a/cli/src/commands/file/list.rs b/cli/src/commands/file/list.rs index 74b7ed6f06..634157d2e1 100644 --- a/cli/src/commands/file/list.rs +++ b/cli/src/commands/file/list.rs @@ -32,23 +32,6 @@ pub(crate) struct FileListArgs { paths: Vec, } -#[instrument(skip_all)] -pub(crate) fn deprecated_cmd_files( - ui: &mut Ui, - command: &CommandHelper, - args: &FileListArgs, -) -> Result<(), CommandError> { - writeln!( - ui.warning_default(), - "`jj files` is deprecated; use `jj file list` instead, which is equivalent" - )?; - writeln!( - ui.warning_default(), - "`jj files` will be removed in a future version, and this will be a hard error" - )?; - cmd_file_list(ui, command, args) -} - #[instrument(skip_all)] pub(crate) fn cmd_file_list( ui: &mut Ui, diff --git a/cli/src/commands/file/show.rs b/cli/src/commands/file/show.rs index e1c572aabe..18eb3e64d1 100644 --- a/cli/src/commands/file/show.rs +++ b/cli/src/commands/file/show.rs @@ -48,23 +48,6 @@ pub(crate) struct FileShowArgs { paths: Vec, } -#[instrument(skip_all)] -pub(crate) fn deprecated_cmd_cat( - ui: &mut Ui, - command: &CommandHelper, - args: &FileShowArgs, -) -> Result<(), CommandError> { - writeln!( - ui.warning_default(), - "`jj cat` is deprecated; use `jj file show` instead, which is equivalent" - )?; - writeln!( - ui.warning_default(), - "`jj cat` will be removed in a future version, and this will be a hard error" - )?; - cmd_file_show(ui, command, args) -} - #[instrument(skip_all)] pub(crate) fn cmd_file_show( ui: &mut Ui, diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 4ca8e02d54..b031dc3d54 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -178,9 +178,15 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co #[cfg(feature = "bench")] Command::Bench(args) => bench::cmd_bench(ui, command_helper, args), Command::Branch(args) => branch::cmd_branch(ui, command_helper, args), - Command::Cat(args) => file::show::deprecated_cmd_cat(ui, command_helper, args), + Command::Cat(args) => { + let cmd = renamed_cmd("cat", "file show", file::show::cmd_file_show); + cmd(ui, command_helper, args) + } Command::Checkout(args) => checkout::cmd_checkout(ui, command_helper, args), - Command::Chmod(args) => file::chmod::deprecated_cmd_chmod(ui, command_helper, args), + Command::Chmod(args) => { + let cmd = renamed_cmd("chmod", "file chmod", file::chmod::cmd_file_chmod); + cmd(ui, command_helper, args) + } Command::Commit(args) => commit::cmd_commit(ui, command_helper, args), Command::Config(args) => config::cmd_config(ui, command_helper, args), Command::Debug(args) => debug::cmd_debug(ui, command_helper, args), @@ -190,7 +196,10 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co Command::Duplicate(args) => duplicate::cmd_duplicate(ui, command_helper, args), Command::Edit(args) => edit::cmd_edit(ui, command_helper, args), Command::File(args) => file::cmd_file(ui, command_helper, args), - Command::Files(args) => file::list::deprecated_cmd_files(ui, command_helper, args), + Command::Files(args) => { + let cmd = renamed_cmd("files", "file list", file::list::cmd_file_list); + cmd(ui, command_helper, args) + } Command::Fix(args) => fix::cmd_fix(ui, command_helper, args), Command::Git(args) => git::cmd_git(ui, command_helper, args), Command::Init(args) => init::cmd_init(ui, command_helper, args), @@ -225,6 +234,25 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co } } +/// Wraps deprecated command of `old_name` which has been renamed to `new_name`. +fn renamed_cmd( + old_name: &'static str, + new_name: &'static str, + cmd: impl Fn(&mut Ui, &CommandHelper, &Args) -> Result<(), CommandError>, +) -> impl Fn(&mut Ui, &CommandHelper, &Args) -> Result<(), CommandError> { + move |ui: &mut Ui, command: &CommandHelper, args: &Args| -> Result<(), CommandError> { + writeln!( + ui.warning_default(), + "`jj {old_name}` is deprecated; use `jj {new_name}` instead, which is equivalent" + )?; + writeln!( + ui.warning_default(), + "`jj {old_name}` will be removed in a future version, and this will be a hard error" + )?; + cmd(ui, command, args) + } +} + fn revert() -> Result<(), CommandError> { Err(user_error_with_hint( "No such subcommand: revert",