From 6ae2e4c54f89c3ed5c0a1ab37271397f87c120e9 Mon Sep 17 00:00:00 2001 From: Antoine Cezar Date: Thu, 2 Nov 2023 16:57:54 +0100 Subject: [PATCH] commands: move run code to run.rs --- cli/src/commands/mod.rs | 33 +++-------------------------- cli/src/commands/run.rs | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 cli/src/commands/run.rs diff --git a/cli/src/commands/mod.rs b/cli/src/commands/mod.rs index 167deb232..843976850 100644 --- a/cli/src/commands/mod.rs +++ b/cli/src/commands/mod.rs @@ -43,6 +43,7 @@ mod prev; mod rebase; mod resolve; mod restore; +mod run; use std::collections::HashSet; use std::fmt::Debug; @@ -130,7 +131,7 @@ enum Commands { Restore(restore::RestoreArgs), #[command(hide = true)] // TODO: Flesh out. - Run(RunArgs), + Run(run::RunArgs), Show(ShowArgs), #[command(subcommand)] Sparse(SparseArgs), @@ -233,29 +234,6 @@ struct UnsquashArgs { interactive: bool, } -/// Run a command across a set of revisions. -/// -/// -/// All recorded state will be persisted in the `.jj` directory, so occasionally -/// a `jj run --clean` is needed to clean up disk space. -/// -/// # Example -/// -/// # Run pre-commit on your local work -/// $ jj run 'pre-commit.py .github/pre-commit.yaml' -r (main..@) -j 4 -/// -/// This allows pre-commit integration and other funny stuff. -#[derive(clap::Args, Clone, Debug)] -#[command(verbatim_doc_comment)] -struct RunArgs { - /// The command to run across all selected revisions. - #[arg(long, short, alias = "x")] - command: String, - /// The revisions to change. - #[arg(long, short, default_value = "@")] - revisions: Vec, -} - /// Split a revision in two /// /// Starts a diff editor (`meld` by default) on the changes in the revision. @@ -1149,11 +1127,6 @@ don't make any changes, then the operation will be aborted. Ok(()) } -// TODO: Move to run.rs -fn cmd_run(_ui: &mut Ui, _command: &CommandHelper, _args: &RunArgs) -> Result<(), CommandError> { - Err(user_error("This is a stub, do not use")) -} - fn make_branch_term(branch_names: &[impl fmt::Display]) -> String { match branch_names { [branch_name] => format!("branch {}", branch_name), @@ -1558,7 +1531,7 @@ pub fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), Co Commands::Squash(sub_args) => cmd_squash(ui, command_helper, sub_args), Commands::Unsquash(sub_args) => cmd_unsquash(ui, command_helper, sub_args), Commands::Restore(sub_args) => restore::cmd_restore(ui, command_helper, sub_args), - Commands::Run(sub_args) => cmd_run(ui, command_helper, sub_args), + Commands::Run(sub_args) => run::cmd_run(ui, command_helper, sub_args), Commands::Diffedit(sub_args) => diffedit::cmd_diffedit(ui, command_helper, sub_args), Commands::Split(sub_args) => cmd_split(ui, command_helper, sub_args), Commands::Merge(sub_args) => merge::cmd_merge(ui, command_helper, sub_args), diff --git a/cli/src/commands/run.rs b/cli/src/commands/run.rs new file mode 100644 index 000000000..de6fe1356 --- /dev/null +++ b/cli/src/commands/run.rs @@ -0,0 +1,47 @@ +// Copyright 2020 The Jujutsu Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use crate::cli_util::{user_error, CommandError, CommandHelper, RevisionArg}; +use crate::ui::Ui; + +/// Run a command across a set of revisions. +/// +/// +/// All recorded state will be persisted in the `.jj` directory, so occasionally +/// a `jj run --clean` is needed to clean up disk space. +/// +/// # Example +/// +/// # Run pre-commit on your local work +/// $ jj run 'pre-commit.py .github/pre-commit.yaml' -r (main..@) -j 4 +/// +/// This allows pre-commit integration and other funny stuff. +#[derive(clap::Args, Clone, Debug)] +#[command(verbatim_doc_comment)] +pub(crate) struct RunArgs { + /// The command to run across all selected revisions. + #[arg(long, short, alias = "x")] + command: String, + /// The revisions to change. + #[arg(long, short, default_value = "@")] + revisions: Vec, +} + +pub(crate) fn cmd_run( + _ui: &mut Ui, + _command: &CommandHelper, + _args: &RunArgs, +) -> Result<(), CommandError> { + Err(user_error("This is a stub, do not use")) +}