diff --git a/src/bin/git-add-coauthor.rs b/src/bin/git-add-coauthor.rs index d2f75d8..7fcdc8e 100644 --- a/src/bin/git-add-coauthor.rs +++ b/src/bin/git-add-coauthor.rs @@ -1,20 +1,8 @@ use clap::Parser; -use git_mob::{parse_coauthors_file, write_coauthors_file, Author}; - -#[derive(Parser, Debug)] -#[clap(name = "git-add-coauthor", version)] -/// Add a co-author to your git mob. -struct Opt { - /// Co-author initials - initials: String, - /// The name of the co-author, in quotes, e.g. "Foo Bar" - name: String, - /// The email of the co-author - email: String, -} +use git_mob::{cli, parse_coauthors_file, write_coauthors_file, Author}; fn main() { - let opt = Opt::parse(); + let opt = cli::GitAddCoauthor::parse(); let mut authors = parse_coauthors_file().unwrap_or_default(); let new_author = Author { name: opt.name, diff --git a/src/bin/git-delete-coauthor.rs b/src/bin/git-delete-coauthor.rs index f657a27..b90360c 100644 --- a/src/bin/git-delete-coauthor.rs +++ b/src/bin/git-delete-coauthor.rs @@ -1,16 +1,8 @@ use clap::Parser; -use git_mob::{get_available_coauthors, write_coauthors_file}; - -#[derive(Parser, Debug)] -#[clap(name = "git-delete-coauthor", version)] -/// Delete a co-author from your .git-coauthors file -struct Opt { - /// Initials of the co-author to delete - initials: String, -} +use git_mob::{cli, get_available_coauthors, write_coauthors_file}; fn main() { - let opt = Opt::parse(); + let opt = cli::GitDeleteCoauthor::parse(); let mut authors = get_available_coauthors(); authors.remove(&opt.initials); write_coauthors_file(authors); diff --git a/src/bin/git-edit-coauthor.rs b/src/bin/git-edit-coauthor.rs index 60d2388..212cd0e 100644 --- a/src/bin/git-edit-coauthor.rs +++ b/src/bin/git-edit-coauthor.rs @@ -1,23 +1,9 @@ use clap::Parser; -use git_mob::{get_available_coauthors, write_coauthors_file, Author}; +use git_mob::{cli, get_available_coauthors, write_coauthors_file, Author}; use std::process; -#[derive(Parser, Debug)] -#[clap(name = "git-edit-coauthor", version)] -/// Edit a co-author in your .git-coauthors template -struct Opt { - /// Co-author initials - initials: String, - /// The name of the co-author, in quotes, e.g. "Foo Bar" - #[clap(long, required_unless_present("email"))] - name: Option, - /// The email of the co-author - #[clap(long, required_unless_present("name"))] - email: Option, -} - fn main() { - let opt = Opt::parse(); + let opt = cli::GitDeleteCoauthor::parse(); let mut authors = get_available_coauthors(); diff --git a/src/bin/git-mob.rs b/src/bin/git-mob.rs index 68afdea..dcd636d 100644 --- a/src/bin/git-mob.rs +++ b/src/bin/git-mob.rs @@ -1,28 +1,14 @@ use clap::Parser; use git_mob::{ - ensure_commit_template_is_set, get_available_coauthors, get_main_author, set_main_author, + cli, ensure_commit_template_is_set, get_available_coauthors, get_main_author, set_main_author, with_gitmessage_template_path_or_exit, Author, }; use std::fmt::Write; use std::fs; use std::process; -#[derive(Parser, Debug)] -#[clap(version, name = "git-mob")] -/// Assemble a group of co-authors to help you on your coding quest -pub struct Opt { - /// Prints list of available co-authors - #[clap(short, long)] - list: bool, - /// Overwrite the main author - #[clap(short, long)] - overwrite: Option, - /// A list of co-author initials - coauthors: Vec, -} - fn main() { - let args = Opt::parse(); + let args = cli::GitMob::parse(); if args.list { list_coauthors(); diff --git a/src/bin/git-solo.rs b/src/bin/git-solo.rs index b057b0b..867a37b 100644 --- a/src/bin/git-solo.rs +++ b/src/bin/git-solo.rs @@ -1,16 +1,11 @@ use clap::Parser; use git_mob::{ - ensure_commit_template_is_set, get_main_author, with_gitmessage_template_path_or_exit, + cli, ensure_commit_template_is_set, get_main_author, with_gitmessage_template_path_or_exit, }; use std::fs::File; -#[derive(Parser, Debug)] -#[clap(name = "git-solo", version)] -/// Disband the mob and continue working solo. -struct Opt {} - fn main() { - let _opt = Opt::parse(); + let _opt = cli::GitSolo::parse(); let main_author = get_main_author(); println!("{}", main_author); diff --git a/src/cli.rs b/src/cli.rs new file mode 100644 index 0000000..6bfbfd7 --- /dev/null +++ b/src/cli.rs @@ -0,0 +1,56 @@ +use clap::Parser; + +#[derive(Parser, Debug)] +#[clap(version, name = "git-mob")] +/// Assemble a group of co-authors to help you on your coding quest +pub struct GitMob { + /// Prints list of available co-authors + #[clap(short, long)] + pub list: bool, + /// Overwrite the main author + #[clap(short, long)] + pub overwrite: Option, + /// A list of co-author initials + pub coauthors: Vec, +} + +#[derive(Parser, Debug)] +#[clap(name = "git-add-coauthor", version)] +/// Add a co-author to your list of available co-authors +pub struct GitAddCoauthor { + /// Co-author initials + pub initials: String, + /// The name of the co-author, in quotes, e.g. "Foo Bar" + pub name: String, + /// The email of the co-author + pub email: String, +} + +#[derive(Parser, Debug)] +#[clap(name = "git-edit-coauthor", version)] +/// Edit a co-author in your list of available co-authors +pub struct GitEditCoauthor { + /// Co-author initials + pub initials: String, + /// The name of the co-author, in quotes, e.g. "Foo Bar" + pub name: String, + /// The email of the co-author + pub email: String, +} + +#[derive(Parser, Debug)] +#[clap(name = "git-delete-coauthor", version)] +/// Delete a co-author from your list of available co-authors +pub struct GitDeleteCoauthor { + /// Co-author initials + pub initials: String, + /// The name of the co-author, in quotes, e.g. "Foo Bar" + pub name: String, + /// The email of the co-author + pub email: String, +} + +#[derive(Parser, Debug)] +#[clap(name = "git-solo", version)] +/// Disband the mob and continue working solo. +pub struct GitSolo {} diff --git a/src/lib.rs b/src/lib.rs index 56f453d..66eb6ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ use std::io::BufReader; use std::process; use std::string::String; +pub mod cli; + #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Author { pub name: String,