WIP: where was I?

This commit is contained in:
Martin Frost 2025-10-09 21:49:16 +02:00
parent b239eacfa3
commit 6ad4b14b37
3 changed files with 154 additions and 90 deletions

View File

@ -1,29 +1,40 @@
// use clap::CommandFactory;
// use clap_mangen::Man;
// use std::env;
// use std::path::Path;
use clap_mangen::Man;
use std::env;
use std::path::Path;
#[path = "src/cli.rs"]
mod cli;
// macro_rules! generate_manpage {
// ($struct:ident) => {
// let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
// let output_dir = Path::new(&target_dir).join(env::var("PROFILE").unwrap());
macro_rules! generate_manpage {
($struct:ident) => {
let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
let output_dir = Path::new(&target_dir).join(env::var("PROFILE").unwrap());
// let cmd = cli::$struct::command();
// let cmd_name = format!("{}.1", cmd.get_name());
// let man = Man::new(cmd);
// let mut buffer: Vec<u8> = Default::default();
// man.render(&mut buffer)?;
// std::fs::write(output_dir.join(cmd_name), buffer)?;
// };
// }
let cmd = cli::$struct::command();
let cmd_name = format!("{}.1", cmd.get_name());
let man = Man::new(cmd);
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(output_dir.join(cmd_name), buffer)?;
};
}
fn main() -> std::io::Result<()> {
// generate_manpage!(GitMob);
// generate_manpage!(GitSolo);
// generate_manpage!(GitAddCoauthor);
// generate_manpage!(GitEditCoauthor);
// generate_manpage!(GitDeleteCoauthor);
let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
let output_dir = Path::new(&target_dir).join(env::var("PROFILE").unwrap());
let cmd = cli::git_mob_cmd();
let man = Man::new(cmd.clone());
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(output_dir.join("git-mob.1"), buffer)?;
for subcommand in cmd.get_subcommands() {
let man = Man::new(subcommand.clone());
let mut buffer: Vec<u8> = Default::default();
man.render(&mut buffer)?;
std::fs::write(output_dir.join(format!("git-mob-{}.1", subcommand.get_name())), buffer)?;
}
Ok(())
}

View File

@ -1,46 +1,69 @@
use clap::{Arg, arg};
use clap::{Arg, ArgAction};
pub fn git_mob_cmd() -> clap::Command {
clap::Command::new("git-mob")
clap::Command::new("git-mob")
.bin_name("git-mob")
.author("Martin Frost, martin@frost.codes")
.version("0.0.0")
.about("A command-line tool for social coding")
.subcommand(
clap::Command::new("add")
.alias("add-coauthor")
.about("Add a coauthor to the database")
.arg(arg!(<handle> "The coauthor's handle"))
.arg(arg!(<name> "The coauthor's name, in quotes"))
.arg(arg!(<email> "The coauthor's email"))
.arg(Arg::new("add")
.display_order(3)
.exclusive(true)
.help("Add a coauthor to the database")
.long("add-coauthor")
.num_args(3)
.short('a')
.value_names(["handle", "name", "email"])
)
.subcommand(
clap::Command::new("edit")
.alias("edit-coauthor")
.about("Edit a coauthor in the database")
.arg(arg!(<handle> "The coauthor's handle"))
.arg(arg!(<name> "The coauthor's name, in quotes"))
.arg(arg!(<email> "The coauthor's email"))
.arg(Arg::new("edit")
.display_order(3)
.exclusive(true)
.help("Edit a coauthor in the database")
.long("edit-coauthor")
.num_args(3)
.short('e')
.value_names(["handle", "name", "email"])
)
.subcommand(
clap::Command::new("remove")
.alias("remove-coauthor")
.alias("rm")
.about("Remove a coauthor from the database")
.arg(arg!(<handle> "The coauthor's handle"))
.arg(Arg::new("delete")
.display_order(3)
.exclusive(true)
.help("Delete a coauthor from the database")
.long("delete-coauthor")
.short('d')
.value_name("handle")
)
.arg(Arg::new("solo")
.action(ArgAction::SetTrue)
.display_order(1)
.exclusive(true)
.help("Continue on your coding quest by yourself")
.long("solo")
.short('s')
)
.arg(Arg::new("list")
.action(ArgAction::SetTrue)
.display_order(4)
.exclusive(true)
.help("List available coauthors in the database")
.long("list-coauthors")
.short('l')
)
.arg(Arg::new("with")
.conflicts_with_all(["add", "edit", "delete", "solo", "list"])
.exclusive(true)
.help("Choose coauthors to help you on your coding quest")
.long("with")
.num_args(1..)
.short('w')
.display_order(0)
.value_name("handle")
)
.arg(Arg::new("current")
.action(ArgAction::SetTrue)
.display_order(2)
.exclusive(true)
.help("Show current mob (including main author)")
.long("current-mob")
.short('c')
)
.subcommand(
clap::Command::new("solo")
.about("Disband the mob. Continue coding on your own")
.arg_required_else_help(false))
.subcommand(
clap::Command::new("list")
.about("List available coauthors in the database")
.arg_required_else_help(false))
.subcommand(
clap::Command::new("with")
.about("Choose coauthors to join your mob")
.arg_required_else_help(true)
.arg(Arg::new("override").short('o').long("override").help("Override default author").value_name("handle"))
.arg(arg!([handles] "The coauthors you want in your mob").num_args(1..)))
}

View File

@ -12,41 +12,71 @@ use git_mob::{
fn main() {
let matches = cli::git_mob_cmd().get_matches();
match matches.subcommand_name() {
Some("add") => {
let args = matches.subcommand_matches("add").unwrap();
let handle = args.get_one("handle").unwrap();
let name = args.get_one("name").unwrap();
let email = args.get_one("email").unwrap();
add_coauthor(handle, name, email);
},
Some("edit") => {
let args = matches.subcommand_matches("edit").unwrap();
let handle = args.get_one("handle").unwrap();
let name = args.get_one("name").unwrap();
let email = args.get_one("email").unwrap();
edit_coauthor(handle, name, email);
},
Some("remove") => {
let handle = matches.subcommand_matches("remove").unwrap()
.get_one("handle").unwrap();
remove_coauthor(handle);
},
Some("list") => list_coauthors(),
Some("solo") => solo(),
Some("with") => {
let matches = matches.subcommand_matches("with").unwrap();
let handles: Vec<String> =
matches.get_many::<String>("handles").unwrap().map(|s| s.clone()).collect();
println!("matches: {:?}", matches);
if let Some(handle) = matches.get_one::<String>("override") {
override_main_author(handle);
}
write_coauthors_to_gitmessage_file(&handles);
},
_ => println!("Something else"),
if let Some(handles) = matches.get_raw("with") {
println!("with: {:?}", handles);
}
if matches.get_one("solo") == Some(&true) {
solo();
}
if matches.get_one("current") == Some(&true) {
println!("current.");
}
if let Some(add_args) = matches.get_raw("add") {
println!("add: {:?}", add_args);
}
if let Some(edit_args) = matches.get_raw("edit") {
println!("edit: {:?}", edit_args);
}
if let Some(delete_handle) = matches.get_one::<String>("delete") {
println!("delete: {:?}", delete_handle);
}
if matches.get_one("list") == Some(&true) {
list_coauthors();
}
// match matches.subcommand_name() {
// Some("add") => {
// let args = matches.subcommand_matches("add").unwrap();
// let handle = args.get_one("handle").unwrap();
// let name = args.get_one("name").unwrap();
// let email = args.get_one("email").unwrap();
// add_coauthor(handle, name, email);
// },
// Some("edit") => {
// let args = matches.subcommand_matches("edit").unwrap();
// let handle = args.get_one("handle").unwrap();
// let name = args.get_one("name").unwrap();
// let email = args.get_one("email").unwrap();
// edit_coauthor(handle, name, email);
// },
// Some("remove") => {
// let handle = matches.subcommand_matches("remove").unwrap()
// .get_one("handle").unwrap();
// remove_coauthor(handle);
// },
// Some("list") => list_coauthors(),
// Some("solo") => solo(),
// Some("with") => {
// let matches = matches.subcommand_matches("with").unwrap();
// let handles: Vec<String> =
// matches.get_many::<String>("handles").unwrap().map(|s| s.clone()).collect();
// if let Some(handle) = matches.get_one::<String>("override") {
// override_main_author(handle);
// }
// write_coauthors_to_gitmessage_file(&handles);
// },
// _ => println!("Something else"),
// }
}
fn list_coauthors() {