Skip to content

Commit

Permalink
cli: extract helper that issues deprecation warning and invoke comman…
Browse files Browse the repository at this point in the history
…d fn
  • Loading branch information
yuja committed Aug 25, 2024
1 parent 842ebe7 commit 3762f89
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 54 deletions.
17 changes: 0 additions & 17 deletions cli/src/commands/file/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 0 additions & 17 deletions cli/src/commands/file/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 0 additions & 17 deletions cli/src/commands/file/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 31 additions & 3 deletions cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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),
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 3762f89

Please sign in to comment.