Skip to content

Commit

Permalink
cli chore: standardize subcommand function and argument type names
Browse files Browse the repository at this point in the history
Now, the command for `jj git remote add` is `cmd_git_remote_add` and its
argument type is `GitRemoteAddArgs`. This should make it easier to find
the CLI docs and the implementation for commands.

This is how `jj branch` commands were already set up in this way. The
`jj op` commands were also already set up in this way, except the
functions are called e.g. `cmd_op_undo`, I kept this for simplicity.

I was mainly motivated by the `jj file` commands. Most other commands
had functions already named in the above pattern, but used to have
shorter argument type names.
  • Loading branch information
ilyagr committed Jun 28, 2024
1 parent 1273c05 commit e21e5e6
Show file tree
Hide file tree
Showing 31 changed files with 132 additions and 132 deletions.
4 changes: 2 additions & 2 deletions cli/src/commands/debug/fileset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ use crate::ui::Ui;

/// Parse fileset expression
#[derive(clap::Args, Clone, Debug)]
pub struct FilesetArgs {
pub struct DebugFilesetArgs {
#[arg(value_hint = clap::ValueHint::AnyPath)]
path: String,
}

pub fn cmd_debug_fileset(
ui: &mut Ui,
command: &CommandHelper,
args: &FilesetArgs,
args: &DebugFilesetArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let path_converter = workspace_command.path_converter();
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use crate::ui::Ui;

/// Show commit index stats
#[derive(clap::Args, Clone, Debug)]
pub struct IndexArgs {}
pub struct DebugIndexArgs {}

pub fn cmd_debug_index(
ui: &mut Ui,
command: &CommandHelper,
_args: &IndexArgs,
_args: &DebugIndexArgs,
) -> Result<(), CommandError> {
// Resolve the operation without loading the repo, so this command won't
// merge concurrent operations and update the index.
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/local_working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ use crate::ui::Ui;
///
/// This command only works with a standard local-disk working copy.
#[derive(clap::Args, Clone, Debug)]
pub struct LocalWorkingCopyArgs {}
pub struct DebugLocalWorkingCopyArgs {}

pub fn cmd_debug_local_working_copy(
ui: &mut Ui,
command: &CommandHelper,
_args: &LocalWorkingCopyArgs,
_args: &DebugLocalWorkingCopyArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
Expand Down
44 changes: 22 additions & 22 deletions cli/src/commands/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ use std::fmt::Debug;
use clap::Subcommand;
use jj_lib::local_working_copy::LocalWorkingCopy;

use self::fileset::{cmd_debug_fileset, FilesetArgs};
use self::index::{cmd_debug_index, IndexArgs};
use self::local_working_copy::{cmd_debug_local_working_copy, LocalWorkingCopyArgs};
use self::operation::{cmd_debug_operation, OperationArgs};
use self::reindex::{cmd_debug_reindex, ReindexArgs};
use self::revset::{cmd_debug_revset, RevsetArgs};
use self::snapshot::{cmd_debug_snapshot, SnapshotArgs};
use self::template::{cmd_debug_template, TemplateArgs};
use self::tree::{cmd_debug_tree, TreeArgs};
use self::watchman::{cmd_debug_watchman, WatchmanCommand};
use self::working_copy::{cmd_debug_working_copy, WorkingCopyArgs};
use self::fileset::{cmd_debug_fileset, DebugFilesetArgs};
use self::index::{cmd_debug_index, DebugIndexArgs};
use self::local_working_copy::{cmd_debug_local_working_copy, DebugLocalWorkingCopyArgs};
use self::operation::{cmd_debug_operation, DebugOperationArgs};
use self::reindex::{cmd_debug_reindex, DebugReindexArgs};
use self::revset::{cmd_debug_revset, DebugRevsetArgs};
use self::snapshot::{cmd_debug_snapshot, DebugSnapshotArgs};
use self::template::{cmd_debug_template, DebugTemplateArgs};
use self::tree::{cmd_debug_tree, DebugTreeArgs};
use self::watchman::{cmd_debug_watchman, DebugWatchmanCommand};
use self::working_copy::{cmd_debug_working_copy, DebugWorkingCopyArgs};
use crate::cli_util::CommandHelper;
use crate::command_error::{user_error, CommandError};
use crate::ui::Ui;
Expand All @@ -49,19 +49,19 @@ use crate::ui::Ui;
#[derive(Subcommand, Clone, Debug)]
#[command(hide = true)]
pub enum DebugCommand {
Fileset(FilesetArgs),
Index(IndexArgs),
LocalWorkingCopy(LocalWorkingCopyArgs),
Fileset(DebugFilesetArgs),
Index(DebugIndexArgs),
LocalWorkingCopy(DebugLocalWorkingCopyArgs),
#[command(visible_alias = "view")]
Operation(OperationArgs),
Reindex(ReindexArgs),
Revset(RevsetArgs),
Snapshot(SnapshotArgs),
Template(TemplateArgs),
Tree(TreeArgs),
Operation(DebugOperationArgs),
Reindex(DebugReindexArgs),
Revset(DebugRevsetArgs),
Snapshot(DebugSnapshotArgs),
Template(DebugTemplateArgs),
Tree(DebugTreeArgs),
#[command(subcommand)]
Watchman(WatchmanCommand),
WorkingCopy(WorkingCopyArgs),
Watchman(DebugWatchmanCommand),
WorkingCopy(DebugWorkingCopyArgs),
}

pub fn cmd_debug(
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use crate::ui::Ui;

/// Show information about an operation and its view
#[derive(clap::Args, Clone, Debug)]
pub struct OperationArgs {
pub struct DebugOperationArgs {
#[arg(default_value = "@")]
operation: String,
#[arg(long, value_enum, default_value = "all")]
Expand All @@ -46,7 +46,7 @@ pub enum OperationDisplay {
pub fn cmd_debug_operation(
ui: &mut Ui,
command: &CommandHelper,
args: &OperationArgs,
args: &DebugOperationArgs,
) -> Result<(), CommandError> {
// Resolve the operation without loading the repo, so this command can be used
// even if e.g. the view object is broken.
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/reindex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ use crate::ui::Ui;

/// Rebuild commit index
#[derive(clap::Args, Clone, Debug)]
pub struct ReindexArgs {}
pub struct DebugReindexArgs {}

pub fn cmd_debug_reindex(
ui: &mut Ui,
command: &CommandHelper,
_args: &ReindexArgs,
_args: &DebugReindexArgs,
) -> Result<(), CommandError> {
// Resolve the operation without loading the repo. The index might have to
// be rebuilt while loading the repo.
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/revset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ use crate::ui::Ui;

/// Evaluate revset to full commit IDs
#[derive(clap::Args, Clone, Debug)]
pub struct RevsetArgs {
pub struct DebugRevsetArgs {
revision: String,
}

pub fn cmd_debug_revset(
ui: &mut Ui,
command: &CommandHelper,
args: &RevsetArgs,
args: &DebugRevsetArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let workspace_ctx = workspace_command.revset_parse_context();
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ use crate::ui::Ui;

/// Trigger a snapshot in the op log
#[derive(clap::Args, Clone, Debug)]
pub struct SnapshotArgs {}
pub struct DebugSnapshotArgs {}

pub fn cmd_debug_snapshot(
ui: &mut Ui,
command: &CommandHelper,
_args: &SnapshotArgs,
_args: &DebugSnapshotArgs,
) -> Result<(), CommandError> {
// workspace helper will snapshot as needed
command.workspace_helper(ui)?;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ use crate::ui::Ui;

/// Parse a template
#[derive(clap::Args, Clone, Debug)]
pub struct TemplateArgs {
pub struct DebugTemplateArgs {
template: String,
}

pub fn cmd_debug_template(
ui: &mut Ui,
_command: &CommandHelper,
args: &TemplateArgs,
args: &DebugTemplateArgs,
) -> Result<(), CommandError> {
let node = template_parser::parse_template(&args.template)?;
writeln!(ui.stdout(), "{node:#?}")?;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::ui::Ui;

/// List the recursive entries of a tree.
#[derive(clap::Args, Clone, Debug)]
pub struct TreeArgs {
pub struct DebugTreeArgs {
#[arg(long, short = 'r')]
revision: Option<RevisionArg>,
#[arg(long, conflicts_with = "revision")]
Expand All @@ -40,7 +40,7 @@ pub struct TreeArgs {
pub fn cmd_debug_tree(
ui: &mut Ui,
command: &CommandHelper,
args: &TreeArgs,
args: &DebugTreeArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let tree = if let Some(tree_id_hex) = &args.id {
Expand Down
14 changes: 7 additions & 7 deletions cli/src/commands/debug/watchman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::command_error::{user_error, CommandError};
use crate::ui::Ui;

#[derive(Subcommand, Clone, Debug)]
pub enum WatchmanCommand {
pub enum DebugWatchmanCommand {
/// Check whether `watchman` is enabled and whether it's correctly installed
Status,
QueryClock,
Expand All @@ -37,14 +37,14 @@ pub enum WatchmanCommand {
pub fn cmd_debug_watchman(
ui: &mut Ui,
command: &CommandHelper,
subcommand: &WatchmanCommand,
subcommand: &DebugWatchmanCommand,
) -> Result<(), CommandError> {
use jj_lib::local_working_copy::LockedLocalWorkingCopy;

let mut workspace_command = command.workspace_helper(ui)?;
let repo = workspace_command.repo().clone();
match subcommand {
WatchmanCommand::Status => {
DebugWatchmanCommand::Status => {
// TODO(ilyagr): It would be nice to add colors here
let config = match command.settings().fsmonitor_settings()? {
FsmonitorSettings::Watchman(config) => {
Expand Down Expand Up @@ -93,17 +93,17 @@ pub fn cmd_debug_watchman(
}
)?;
}
WatchmanCommand::QueryClock => {
DebugWatchmanCommand::QueryClock => {
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let (clock, _changed_files) = wc.query_watchman(&WatchmanConfig::default())?;
writeln!(ui.stdout(), "Clock: {clock:?}")?;
}
WatchmanCommand::QueryChangedFiles => {
DebugWatchmanCommand::QueryChangedFiles => {
let wc = check_local_disk_wc(workspace_command.working_copy().as_any())?;
let (_clock, changed_files) = wc.query_watchman(&WatchmanConfig::default())?;
writeln!(ui.stdout(), "Changed files: {changed_files:?}")?;
}
WatchmanCommand::ResetClock => {
DebugWatchmanCommand::ResetClock => {
let (mut locked_ws, _commit) = workspace_command.start_working_copy_mutation()?;
let Some(locked_local_wc): Option<&mut LockedLocalWorkingCopy> =
locked_ws.locked_wc().as_any_mut().downcast_mut()
Expand All @@ -124,7 +124,7 @@ pub fn cmd_debug_watchman(
pub fn cmd_debug_watchman(
_ui: &mut Ui,
_command: &CommandHelper,
_subcommand: &WatchmanCommand,
_subcommand: &DebugWatchmanCommand,
) -> Result<(), CommandError> {
Err(user_error(
"Cannot query Watchman because jj was not compiled with the `watchman` feature",
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/debug/working_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use crate::ui::Ui;

/// Show information about the working copy state
#[derive(clap::Args, Clone, Debug)]
pub struct WorkingCopyArgs {}
pub struct DebugWorkingCopyArgs {}

pub fn cmd_debug_working_copy(
ui: &mut Ui,
command: &CommandHelper,
_args: &WorkingCopyArgs,
_args: &DebugWorkingCopyArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper_no_snapshot(ui)?;
let wc = workspace_command.working_copy();
Expand Down
10 changes: 5 additions & 5 deletions cli/src/commands/file/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum ChmodMode {
/// Unlike the POSIX `chmod`, `jj file chmod` also works on Windows, on
/// conflicted files, and on arbitrary revisions.
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct ChmodArgs {
pub(crate) struct FileChmodArgs {
mode: ChmodMode,
/// The revision to update
#[arg(long, short, default_value = "@")]
Expand All @@ -51,7 +51,7 @@ pub(crate) struct ChmodArgs {
pub(crate) fn deprecated_cmd_chmod(
ui: &mut Ui,
command: &CommandHelper,
args: &ChmodArgs,
args: &FileChmodArgs,
) -> Result<(), CommandError> {
writeln!(
ui.warning_default(),
Expand All @@ -61,14 +61,14 @@ pub(crate) fn deprecated_cmd_chmod(
ui.warning_default(),
"`jj chmod` will be removed in a future version, and this will be a hard error"
)?;
cmd_chmod(ui, command, args)
cmd_file_chmod(ui, command, args)
}

#[instrument(skip_all)]
pub(crate) fn cmd_chmod(
pub(crate) fn cmd_file_chmod(
ui: &mut Ui,
command: &CommandHelper,
args: &ChmodArgs,
args: &FileChmodArgs,
) -> Result<(), CommandError> {
let executable_bit = match args.mode {
ChmodMode::Executable => true,
Expand Down
10 changes: 5 additions & 5 deletions cli/src/commands/file/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::ui::Ui;

/// List files in a revision
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct ListArgs {
pub(crate) struct FileListArgs {
/// The revision to list files in
#[arg(long, short, default_value = "@")]
revision: RevisionArg,
Expand All @@ -35,7 +35,7 @@ pub(crate) struct ListArgs {
pub(crate) fn deprecated_cmd_files(
ui: &mut Ui,
command: &CommandHelper,
args: &ListArgs,
args: &FileListArgs,
) -> Result<(), CommandError> {
writeln!(
ui.warning_default(),
Expand All @@ -45,14 +45,14 @@ pub(crate) fn deprecated_cmd_files(
ui.warning_default(),
"`jj files` will be removed in a future version, and this will be a hard error"
)?;
cmd_list(ui, command, args)
cmd_file_list(ui, command, args)
}

#[instrument(skip_all)]
pub(crate) fn cmd_list(
pub(crate) fn cmd_file_list(
ui: &mut Ui,
command: &CommandHelper,
args: &ListArgs,
args: &FileListArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&args.revision)?;
Expand Down
12 changes: 6 additions & 6 deletions cli/src/commands/file/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use crate::ui::Ui;
/// File operations.
#[derive(clap::Subcommand, Clone, Debug)]
pub enum FileCommand {
Chmod(chmod::ChmodArgs),
List(list::ListArgs),
Show(show::ShowArgs),
Chmod(chmod::FileChmodArgs),
List(list::FileListArgs),
Show(show::FileShowArgs),
}

pub fn cmd_file(
Expand All @@ -34,8 +34,8 @@ pub fn cmd_file(
subcommand: &FileCommand,
) -> Result<(), CommandError> {
match subcommand {
FileCommand::Chmod(args) => chmod::cmd_chmod(ui, command, args),
FileCommand::List(args) => list::cmd_list(ui, command, args),
FileCommand::Show(args) => show::cmd_show(ui, command, args),
FileCommand::Chmod(args) => chmod::cmd_file_chmod(ui, command, args),
FileCommand::List(args) => list::cmd_file_list(ui, command, args),
FileCommand::Show(args) => show::cmd_file_show(ui, command, args),
}
}
Loading

0 comments on commit e21e5e6

Please sign in to comment.