WIP: where was I?
This commit is contained in:
parent
b239eacfa3
commit
6ad4b14b37
53
build.rs
53
build.rs
|
|
@ -1,29 +1,40 @@
|
||||||
// use clap::CommandFactory;
|
use clap_mangen::Man;
|
||||||
// use clap_mangen::Man;
|
use std::env;
|
||||||
// use std::env;
|
use std::path::Path;
|
||||||
// use std::path::Path;
|
|
||||||
|
|
||||||
|
#[path = "src/cli.rs"]
|
||||||
|
mod cli;
|
||||||
|
|
||||||
// macro_rules! generate_manpage {
|
macro_rules! generate_manpage {
|
||||||
// ($struct:ident) => {
|
($struct:ident) => {
|
||||||
// let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
|
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 output_dir = Path::new(&target_dir).join(env::var("PROFILE").unwrap());
|
||||||
|
|
||||||
// let cmd = cli::$struct::command();
|
let cmd = cli::$struct::command();
|
||||||
// let cmd_name = format!("{}.1", cmd.get_name());
|
let cmd_name = format!("{}.1", cmd.get_name());
|
||||||
// let man = Man::new(cmd);
|
let man = Man::new(cmd);
|
||||||
// let mut buffer: Vec<u8> = Default::default();
|
let mut buffer: Vec<u8> = Default::default();
|
||||||
// man.render(&mut buffer)?;
|
man.render(&mut buffer)?;
|
||||||
// std::fs::write(output_dir.join(cmd_name), buffer)?;
|
std::fs::write(output_dir.join(cmd_name), buffer)?;
|
||||||
// };
|
};
|
||||||
// }
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
// generate_manpage!(GitMob);
|
let target_dir = env::var("CARGO_TARGET_DIR").unwrap_or("target".to_string());
|
||||||
// generate_manpage!(GitSolo);
|
let output_dir = Path::new(&target_dir).join(env::var("PROFILE").unwrap());
|
||||||
// generate_manpage!(GitAddCoauthor);
|
|
||||||
// generate_manpage!(GitEditCoauthor);
|
let cmd = cli::git_mob_cmd();
|
||||||
// generate_manpage!(GitDeleteCoauthor);
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
95
src/cli.rs
95
src/cli.rs
|
|
@ -1,46 +1,69 @@
|
||||||
use clap::{Arg, arg};
|
use clap::{Arg, ArgAction};
|
||||||
|
|
||||||
pub fn git_mob_cmd() -> clap::Command {
|
pub fn git_mob_cmd() -> clap::Command {
|
||||||
clap::Command::new("git-mob")
|
clap::Command::new("git-mob")
|
||||||
.bin_name("git-mob")
|
.bin_name("git-mob")
|
||||||
.author("Martin Frost, martin@frost.codes")
|
.author("Martin Frost, martin@frost.codes")
|
||||||
.version("0.0.0")
|
.version("0.0.0")
|
||||||
.about("A command-line tool for social coding")
|
.about("A command-line tool for social coding")
|
||||||
.subcommand(
|
.arg(Arg::new("add")
|
||||||
clap::Command::new("add")
|
.display_order(3)
|
||||||
.alias("add-coauthor")
|
.exclusive(true)
|
||||||
.about("Add a coauthor to the database")
|
.help("Add a coauthor to the database")
|
||||||
.arg(arg!(<handle> "The coauthor's handle"))
|
.long("add-coauthor")
|
||||||
.arg(arg!(<name> "The coauthor's name, in quotes"))
|
.num_args(3)
|
||||||
.arg(arg!(<email> "The coauthor's email"))
|
.short('a')
|
||||||
|
.value_names(["handle", "name", "email"])
|
||||||
)
|
)
|
||||||
.subcommand(
|
.arg(Arg::new("edit")
|
||||||
clap::Command::new("edit")
|
.display_order(3)
|
||||||
.alias("edit-coauthor")
|
.exclusive(true)
|
||||||
.about("Edit a coauthor in the database")
|
.help("Edit a coauthor in the database")
|
||||||
.arg(arg!(<handle> "The coauthor's handle"))
|
.long("edit-coauthor")
|
||||||
.arg(arg!(<name> "The coauthor's name, in quotes"))
|
.num_args(3)
|
||||||
.arg(arg!(<email> "The coauthor's email"))
|
.short('e')
|
||||||
|
.value_names(["handle", "name", "email"])
|
||||||
)
|
)
|
||||||
.subcommand(
|
.arg(Arg::new("delete")
|
||||||
clap::Command::new("remove")
|
.display_order(3)
|
||||||
.alias("remove-coauthor")
|
.exclusive(true)
|
||||||
.alias("rm")
|
.help("Delete a coauthor from the database")
|
||||||
.about("Remove a coauthor from the database")
|
.long("delete-coauthor")
|
||||||
.arg(arg!(<handle> "The coauthor's handle"))
|
.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..)))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
96
src/main.rs
96
src/main.rs
|
|
@ -12,41 +12,71 @@ use git_mob::{
|
||||||
fn main() {
|
fn main() {
|
||||||
let matches = cli::git_mob_cmd().get_matches();
|
let matches = cli::git_mob_cmd().get_matches();
|
||||||
|
|
||||||
match matches.subcommand_name() {
|
println!("matches: {:?}", matches);
|
||||||
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") {
|
if let Some(handles) = matches.get_raw("with") {
|
||||||
override_main_author(handle);
|
println!("with: {:?}", handles);
|
||||||
}
|
|
||||||
|
|
||||||
write_coauthors_to_gitmessage_file(&handles);
|
|
||||||
},
|
|
||||||
_ => println!("Something else"),
|
|
||||||
}
|
}
|
||||||
|
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() {
|
fn list_coauthors() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue