just playing with tangled
at ig/vimdiffwarn 64 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; 18use jj_cli::cli_util::CommandHelper; 19use jj_cli::cli_util::RevisionArg; 20use jj_cli::command_error::CommandError; 21use jj_cli::ui::Ui; 22 23#[derive(clap::Parser, Clone, Debug)] 24enum CustomCommand { 25 Frobnicate(FrobnicateArgs), 26} 27 28/// Frobnicate a revisions 29#[derive(clap::Args, Clone, Debug)] 30struct FrobnicateArgs { 31 /// The revision to frobnicate 32 #[arg(default_value = "@")] 33 revision: RevisionArg, 34} 35 36fn run_custom_command( 37 ui: &mut Ui, 38 command_helper: &CommandHelper, 39 command: CustomCommand, 40) -> Result<(), CommandError> { 41 match command { 42 CustomCommand::Frobnicate(args) => { 43 let mut workspace_command = command_helper.workspace_helper(ui)?; 44 let commit = workspace_command.resolve_single_rev(ui, &args.revision)?; 45 let mut tx = workspace_command.start_transaction(); 46 let new_commit = tx 47 .repo_mut() 48 .rewrite_commit(&commit) 49 .set_description("Frobnicated!") 50 .write()?; 51 tx.finish(ui, "frobnicate")?; 52 writeln!( 53 ui.status(), 54 "Frobnicated revision: {}", 55 workspace_command.format_commit_summary(&new_commit) 56 )?; 57 Ok(()) 58 } 59 } 60} 61 62fn main() -> std::process::ExitCode { 63 CliRunner::init().add_subcommand(run_custom_command).run() 64}