Skip to content

Commit

Permalink
feat: add with subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubashwer committed Mar 12, 2023
1 parent bc5ba48 commit e860988
Showing 1 changed file with 58 additions and 1 deletion.
59 changes: 58 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
use std::process::Command;
use std::str;

use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
With { coauthor_keys: Option<Vec<String>> },
}

fn main() {
println!("Hello, world!");
let cli = Cli::parse();

match &cli.command {
Commands::With { coauthor_keys } => {
Command::new("git")
.arg("config")
.arg("--global")
.arg("--remove-section")
.arg(format!("co-authors.active"))
.output()
.expect("failed to execute process");

match coauthor_keys {
Some(keys) => {
for key in keys {
let output = Command::new("git")
.arg("config")
.arg("--global")
.arg(format!("chums.{key}"))
.output()
.expect("failed to execute process");

assert!(output.status.success());

let status = Command::new("git")
.arg("config")
.arg("--global")
.arg(format!("chums.active.{key}"))
.arg(str::from_utf8(&output.stdout).unwrap().trim())
.status()
.expect("failed to execute process");

assert!(status.success());
}
return;
}
None => println!("No co-author keys provided"),
}
}
}
}

0 comments on commit e860988

Please sign in to comment.