Skip to content

Commit

Permalink
completion: teach commands about revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor committed Nov 16, 2024
1 parent 68c0fd6 commit dd6479f
Show file tree
Hide file tree
Showing 27 changed files with 226 additions and 45 deletions.
4 changes: 3 additions & 1 deletion cli/src/commands/abandon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::io::Write;

use clap_complete::ArgValueCandidates;
use itertools::Itertools as _;
use jj_lib::commit::CommitIteratorExt;
use jj_lib::object_id::ObjectId;
Expand All @@ -22,6 +23,7 @@ use tracing::instrument;
use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// Abandon a revision
Expand All @@ -35,7 +37,7 @@ use crate::ui::Ui;
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct AbandonArgs {
/// The revision(s) to abandon
#[arg(default_value = "@")]
#[arg(default_value = "@", add = ArgValueCandidates::new(complete::mutable_revisions))]
revisions: Vec<RevisionArg>,
/// Do not print every abandoned commit on a separate line
#[arg(long, short)]
Expand Down
14 changes: 12 additions & 2 deletions cli/src/commands/backout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use clap_complete::ArgValueCandidates;
use itertools::Itertools as _;
use jj_lib::object_id::ObjectId;
use jj_lib::rewrite::merge_commit_trees;
Expand All @@ -20,18 +21,27 @@ use tracing::instrument;
use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// Apply the reverse of a revision on top of another revision
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct BackoutArgs {
/// The revision(s) to apply the reverse of
#[arg(long, short, default_value = "@")]
#[arg(
long, short,
default_value = "@",
add = ArgValueCandidates::new(complete::all_revisions),
)]
revisions: Vec<RevisionArg>,
/// The revision to apply the reverse changes on top of
// TODO: It seems better to default this to `@-`. Maybe the working
// copy should be rebased on top?
#[arg(long, short, default_value = "@")]
#[arg(
long, short,
default_value = "@",
add = ArgValueCandidates::new(complete::all_revisions),
)]
destination: Vec<RevisionArg>,
}

Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::collections::HashMap;
use std::io;
use std::io::Read;

use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::backend::Signature;
use jj_lib::commit::CommitIteratorExt;
Expand All @@ -26,6 +27,7 @@ use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::user_error;
use crate::command_error::CommandError;
use crate::complete;
use crate::description_util::description_template;
use crate::description_util::edit_description;
use crate::description_util::edit_multiple_descriptions;
Expand All @@ -42,7 +44,7 @@ use crate::ui::Ui;
#[command(alias = "desc")]
pub(crate) struct DescribeArgs {
/// The revision(s) whose description to edit
#[arg(default_value = "@")]
#[arg(default_value = "@", add = ArgValueCandidates::new(complete::mutable_revisions))]
revisions: Vec<RevisionArg>,
/// Ignored (but lets you pass `-r` for consistency with other commands)
#[arg(short = 'r', hide = true, action = clap::ArgAction::Count)]
Expand Down
8 changes: 5 additions & 3 deletions cli/src/commands/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::copies::CopyRecords;
use jj_lib::repo::Repo;
Expand All @@ -22,6 +23,7 @@ use crate::cli_util::print_unmatched_explicit_paths;
use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::complete;
use crate::diff_util::get_copy_records;
use crate::diff_util::DiffFormatArgs;
use crate::ui::Ui;
Expand All @@ -46,13 +48,13 @@ pub(crate) struct DiffArgs {
/// If the revision is a merge commit, this shows changes *from* the
/// automatic merge of the contents of all of its parents *to* the contents
/// of the revision itself.
#[arg(long, short)]
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
revision: Option<RevisionArg>,
/// Show changes from this revision
#[arg(long, conflicts_with = "revision")]
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
from: Option<RevisionArg>,
/// Show changes to this revision
#[arg(long, conflicts_with = "revision")]
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
to: Option<RevisionArg>,
/// Restrict the diff to these paths
#[arg(value_hint = clap::ValueHint::AnyPath)]
Expand Down
8 changes: 5 additions & 3 deletions cli/src/commands/diffedit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use std::io::Write;

use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::matchers::EverythingMatcher;
use jj_lib::object_id::ObjectId;
Expand All @@ -23,6 +24,7 @@ use tracing::instrument;
use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// Touch up the content changes in a revision with a diff editor
Expand All @@ -48,17 +50,17 @@ pub(crate) struct DiffeditArgs {
/// The revision to touch up
///
/// Defaults to @ if neither --to nor --from are specified.
#[arg(long, short)]
#[arg(long, short, add = ArgValueCandidates::new(complete::mutable_revisions))]
revision: Option<RevisionArg>,
/// Show changes from this revision
///
/// Defaults to @ if --to is specified.
#[arg(long, conflicts_with = "revision")]
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::all_revisions))]
from: Option<RevisionArg>,
/// Edit changes in this revision
///
/// Defaults to @ if --from is specified.
#[arg(long, conflicts_with = "revision")]
#[arg(long, conflicts_with = "revision", add = ArgValueCandidates::new(complete::mutable_revisions))]
to: Option<RevisionArg>,
/// Specify diff editor to be used
#[arg(long, value_name = "NAME")]
Expand Down
12 changes: 8 additions & 4 deletions cli/src/commands/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::io::Write;
use std::rc::Rc;

use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::backend::CommitId;
use jj_lib::commit::CommitIteratorExt;
Expand All @@ -32,6 +33,7 @@ use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::user_error;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// Create new changes with the same content as existing ones
Expand All @@ -50,22 +52,23 @@ use crate::ui::Ui;
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct DuplicateArgs {
/// The revision(s) to duplicate
#[arg(default_value = "@")]
#[arg(default_value = "@", add = ArgValueCandidates::new(complete::all_revisions))]
revisions: Vec<RevisionArg>,
/// Ignored (but lets you pass `-r` for consistency with other commands)
#[arg(short = 'r', hide = true, action = clap::ArgAction::Count)]
unused_revision: u8,
/// The revision(s) to duplicate onto (can be repeated to create a merge
/// commit)
#[arg(long, short)]
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
destination: Vec<RevisionArg>,
/// The revision(s) to insert after (can be repeated to create a merge
/// commit)
#[arg(
long,
short = 'A',
visible_alias = "after",
conflicts_with = "destination"
conflicts_with = "destination",
add = ArgValueCandidates::new(complete::all_revisions),
)]
insert_after: Vec<RevisionArg>,
/// The revision(s) to insert before (can be repeated to create a merge
Expand All @@ -74,7 +77,8 @@ pub(crate) struct DuplicateArgs {
long,
short = 'B',
visible_alias = "before",
conflicts_with = "destination"
conflicts_with = "destination",
add = ArgValueCandidates::new(complete::mutable_revisions)
)]
insert_before: Vec<RevisionArg>,
}
Expand Down
3 changes: 3 additions & 0 deletions cli/src/commands/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

use std::io::Write;

use clap_complete::ArgValueCandidates;
use jj_lib::object_id::ObjectId;
use tracing::instrument;

use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// Sets the specified revision as the working-copy revision
Expand All @@ -31,6 +33,7 @@ use crate::ui::Ui;
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct EditArgs {
/// The commit to edit
#[arg(add = ArgValueCandidates::new(complete::mutable_revisions))]
revision: RevisionArg,
/// Ignored (but lets you pass `-r` for consistency with other commands)
#[arg(short = 'r', hide = true)]
Expand Down
8 changes: 7 additions & 1 deletion cli/src/commands/evolog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use clap_complete::ArgValueCandidates;
use itertools::Itertools;
use jj_lib::commit::Commit;
use jj_lib::dag_walk::topo_order_reverse_ok;
Expand All @@ -25,6 +26,7 @@ use crate::cli_util::LogContentFormat;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::commit_templater::CommitTemplateLanguage;
use crate::complete;
use crate::diff_util::DiffFormatArgs;
use crate::graphlog::get_graphlog;
use crate::graphlog::Edge;
Expand All @@ -37,7 +39,11 @@ use crate::ui::Ui;
/// of a change evolves when the change is updated, rebased, etc.
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct EvologArgs {
#[arg(long, short, default_value = "@")]
#[arg(
long, short,
default_value = "@",
add = ArgValueCandidates::new(complete::all_revisions),
)]
revision: RevisionArg,
/// Limit number of revisions to show
#[arg(long, short = 'n')]
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/file/annotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use clap_complete::ArgValueCandidates;
use jj_lib::annotate::get_annotation_for_file;
use jj_lib::annotate::FileAnnotation;
use jj_lib::commit::Commit;
Expand All @@ -23,6 +24,7 @@ use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::user_error;
use crate::command_error::CommandError;
use crate::complete;
use crate::templater::TemplateRenderer;
use crate::ui::Ui;

Expand All @@ -38,7 +40,7 @@ pub(crate) struct FileAnnotateArgs {
#[arg(value_hint = clap::ValueHint::AnyPath)]
path: String,
/// an optional revision to start at
#[arg(long, short)]
#[arg(long, short, add = ArgValueCandidates::new(complete::all_revisions))]
revision: Option<RevisionArg>,
}

Expand Down
8 changes: 7 additions & 1 deletion cli/src/commands/file/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use clap_complete::ArgValueCandidates;
use jj_lib::backend::TreeValue;
use jj_lib::merged_tree::MergedTreeBuilder;
use jj_lib::object_id::ObjectId;
Expand All @@ -22,6 +23,7 @@ use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::user_error;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
Expand All @@ -43,7 +45,11 @@ enum ChmodMode {
pub(crate) struct FileChmodArgs {
mode: ChmodMode,
/// The revision to update
#[arg(long, short, default_value = "@")]
#[arg(
long, short,
default_value = "@",
add = ArgValueCandidates::new(complete::mutable_revisions),
)]
revision: RevisionArg,
/// Paths to change the executable bit for
#[arg(required = true, value_hint = clap::ValueHint::AnyPath)]
Expand Down
8 changes: 7 additions & 1 deletion cli/src/commands/file/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@

use std::io::Write;

use clap_complete::ArgValueCandidates;
use tracing::instrument;

use crate::cli_util::CommandHelper;
use crate::cli_util::RevisionArg;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// List files in a revision
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct FileListArgs {
/// The revision to list files in
#[arg(long, short, default_value = "@")]
#[arg(
long, short,
default_value = "@",
add = ArgValueCandidates::new(complete::all_revisions),
)]
revision: RevisionArg,
/// Only list files matching these prefixes (instead of all files)
#[arg(value_hint = clap::ValueHint::AnyPath)]
Expand Down
8 changes: 7 additions & 1 deletion cli/src/commands/file/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::io;
use std::io::Write;

use clap_complete::ArgValueCandidates;
use jj_lib::backend::BackendResult;
use jj_lib::conflicts::materialize_merge_result;
use jj_lib::conflicts::materialize_tree_value;
Expand All @@ -33,6 +34,7 @@ use crate::cli_util::RevisionArg;
use crate::cli_util::WorkspaceCommandHelper;
use crate::command_error::user_error;
use crate::command_error::CommandError;
use crate::complete;
use crate::ui::Ui;

/// Print contents of files in a revision
Expand All @@ -42,7 +44,11 @@ use crate::ui::Ui;
#[derive(clap::Args, Clone, Debug)]
pub(crate) struct FileShowArgs {
/// The revision to get the file contents from
#[arg(long, short, default_value = "@")]
#[arg(
long, short,
default_value = "@",
add = ArgValueCandidates::new(complete::all_revisions),
)]
revision: RevisionArg,
/// Paths to print
#[arg(required = true, value_hint = clap::ValueHint::FilePath)]
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::io::Write;
use std::process::Stdio;
use std::sync::mpsc::channel;

use clap_complete::ArgValueCandidates;
use futures::StreamExt;
use itertools::Itertools;
use jj_lib::backend::BackendError;
Expand Down Expand Up @@ -49,6 +50,7 @@ use crate::cli_util::RevisionArg;
use crate::command_error::config_error;
use crate::command_error::print_parse_diagnostics;
use crate::command_error::CommandError;
use crate::complete;
use crate::config::to_toml_value;
use crate::config::CommandNameAndArgs;
use crate::ui::Ui;
Expand Down Expand Up @@ -124,7 +126,7 @@ pub(crate) struct FixArgs {
/// Fix files in the specified revision(s) and their descendants. If no
/// revisions are specified, this defaults to the `revsets.fix` setting, or
/// `reachable(@, mutable())` if it is not set.
#[arg(long, short)]
#[arg(long, short, add = ArgValueCandidates::new(complete::mutable_revisions))]
source: Vec<RevisionArg>,
/// Fix only these paths
#[arg(value_hint = clap::ValueHint::AnyPath)]
Expand Down
Loading

0 comments on commit dd6479f

Please sign in to comment.