2022-11-26 23:57:50 +00:00
|
|
|
// Copyright 2022 The Jujutsu Authors
|
2022-07-15 20:52:14 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2023-06-28 14:12:40 +00:00
|
|
|
use jj_cli::cli_util::{CliRunner, CommandError, CommandHelper};
|
|
|
|
use jj_cli::ui::Ui;
|
2022-07-15 20:52:14 +00:00
|
|
|
|
|
|
|
#[derive(clap::Parser, Clone, Debug)]
|
|
|
|
enum CustomCommands {
|
|
|
|
Frobnicate(FrobnicateArgs),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Frobnicate a revisions
|
|
|
|
#[derive(clap::Args, Clone, Debug)]
|
|
|
|
struct FrobnicateArgs {
|
|
|
|
/// The revision to frobnicate
|
2022-09-29 17:42:28 +00:00
|
|
|
#[arg(default_value = "@")]
|
2022-07-15 20:52:14 +00:00
|
|
|
revision: String,
|
|
|
|
}
|
|
|
|
|
2023-01-03 12:53:30 +00:00
|
|
|
fn run_custom_command(
|
2023-01-03 08:33:53 +00:00
|
|
|
ui: &mut Ui,
|
2023-01-03 12:48:48 +00:00
|
|
|
command_helper: &CommandHelper,
|
2023-01-03 12:53:30 +00:00
|
|
|
command: CustomCommands,
|
2023-01-03 08:33:53 +00:00
|
|
|
) -> Result<(), CommandError> {
|
2023-01-03 12:53:30 +00:00
|
|
|
match command {
|
|
|
|
CustomCommands::Frobnicate(args) => {
|
2022-07-15 20:52:14 +00:00
|
|
|
let mut workspace_command = command_helper.workspace_helper(ui)?;
|
2023-07-28 00:33:54 +00:00
|
|
|
let commit = workspace_command.resolve_single_rev(&args.revision, ui)?;
|
2022-07-15 20:52:14 +00:00
|
|
|
let mut tx = workspace_command.start_transaction("Frobnicate");
|
2022-12-25 20:58:08 +00:00
|
|
|
let new_commit = tx
|
|
|
|
.mut_repo()
|
2023-01-04 08:57:36 +00:00
|
|
|
.rewrite_commit(command_helper.settings(), &commit)
|
2022-12-21 09:13:56 +00:00
|
|
|
.set_description("Frobnicated!")
|
2022-12-24 05:09:19 +00:00
|
|
|
.write()?;
|
2023-01-15 08:28:16 +00:00
|
|
|
tx.finish(ui)?;
|
2022-07-15 20:52:14 +00:00
|
|
|
writeln!(
|
|
|
|
ui,
|
|
|
|
"Frobnicated revision: {}",
|
2023-01-14 09:33:18 +00:00
|
|
|
workspace_command.format_commit_summary(&new_commit)
|
2022-07-15 20:52:14 +00:00
|
|
|
)?;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-19 15:10:18 +00:00
|
|
|
fn main() -> std::process::ExitCode {
|
|
|
|
CliRunner::init().add_subcommand(run_custom_command).run()
|
2022-07-15 20:52:14 +00:00
|
|
|
}
|