just playing with tangled
at diffedit3 62 lines 2.0 kB view raw
1// Copyright 2022 The Jujutsu Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// https://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15use std::io::Write as _; 16 17use jj_cli::cli_util::{CliRunner, CommandHelper, RevisionArg}; 18use jj_cli::command_error::CommandError; 19use jj_cli::ui::Ui; 20 21#[derive(clap::Parser, Clone, Debug)] 22enum CustomCommand { 23 Frobnicate(FrobnicateArgs), 24} 25 26/// Frobnicate a revisions 27#[derive(clap::Args, Clone, Debug)] 28struct FrobnicateArgs { 29 /// The revision to frobnicate 30 #[arg(default_value = "@")] 31 revision: RevisionArg, 32} 33 34fn run_custom_command( 35 ui: &mut Ui, 36 command_helper: &CommandHelper, 37 command: CustomCommand, 38) -> Result<(), CommandError> { 39 match command { 40 CustomCommand::Frobnicate(args) => { 41 let mut workspace_command = command_helper.workspace_helper(ui)?; 42 let commit = workspace_command.resolve_single_rev(&args.revision)?; 43 let mut tx = workspace_command.start_transaction(); 44 let new_commit = tx 45 .mut_repo() 46 .rewrite_commit(command_helper.settings(), &commit) 47 .set_description("Frobnicated!") 48 .write()?; 49 tx.finish(ui, "Frobnicate")?; 50 writeln!( 51 ui.status(), 52 "Frobnicated revision: {}", 53 workspace_command.format_commit_summary(&new_commit) 54 )?; 55 Ok(()) 56 } 57 } 58} 59 60fn main() -> std::process::ExitCode { 61 CliRunner::init().add_subcommand(run_custom_command).run() 62}