ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: extract helper that issues deprecation warning and invoke command fn

This commit is contained in:
Yuya Nishihara 2024-08-25 21:12:23 +09:00
parent 842ebe7f92
commit 3762f890f6
4 changed files with 31 additions and 54 deletions

View file

@ -50,23 +50,6 @@ pub(crate) struct FileChmodArgs {
paths: Vec<String>,
}
#[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,

View file

@ -32,23 +32,6 @@ pub(crate) struct FileListArgs {
paths: Vec<String>,
}
#[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,

View file

@ -48,23 +48,6 @@ pub(crate) struct FileShowArgs {
paths: Vec<String>,
}
#[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,

View file

@ -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<Args>(
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",