feat: add -c (copy to clipboard) and -s (sign)

This commit is contained in:
rzmk 2024-12-09 18:22:04 -05:00
parent 1757cb99ff
commit 3e0b97d172
No known key found for this signature in database
6 changed files with 433 additions and 10 deletions

View file

@ -62,7 +62,8 @@ fn main() {
// Confirm the commit message
let confirm =
Confirm::new(format!("Result:\n\n{}\n\nCommit? (y/n):", result_message).as_str()).prompt();
Confirm::new(format!("Result:\n\n{}\n\nRun commands? (y/n):", result_message).as_str())
.prompt();
// If confirmed, run the commands in succession
match confirm {

View file

@ -11,10 +11,18 @@ pub struct Cli {
#[arg(short = 'a', long = "add")]
pub add: bool,
/// Copy commit message to clipboard instead of committing
#[arg(short = 'c', long = "clipboard")]
pub clipboard: bool,
/// Run `git push` after committing
#[arg(short = 'p', long = "push")]
pub push: bool,
/// Add the `-S` flag when running `git commit` for signing
#[arg(short = 's', long = "sign")]
pub sign: bool,
/// Run in debug mode (print output of each command)
#[arg(short = 'd', long = "debug")]
pub debug: bool,

View file

@ -1,4 +1,5 @@
use super::parser::Cli;
use arboard::Clipboard;
use std::process::Command;
// Run the commands in succession
@ -8,12 +9,25 @@ pub fn orchestrate_commit(cli: &Cli, message: &str) {
run(cli, "git", &["add", "-A"]);
}
println!("Running git commit -m \"{}\"", message);
run(cli, "git", &["commit", "-m", message]);
if cli.clipboard {
println!("Copying commit message to clipboard");
if !cli.dry_run {
let mut clipboard = Clipboard::new().unwrap();
clipboard.set_text(message).unwrap();
}
} else {
println!("Running git commit -m \"{}\"", message);
let args = if cli.sign {
vec!["commit", "-m", message]
} else {
vec!["commit", "-S", "-m", message]
};
run(cli, "git", &args);
if cli.push {
println!("Running git push");
run(cli, "git", &["push"]);
if cli.push {
println!("Running git push");
run(cli, "git", &["push"]);
}
}
println!("Done 🎉");