Extract clap args definitions to common cli module
Keeping these definitions separate from the implementations will help generating man pages for the executables without putting _all_ of the dependencies into the build-dependencies.
This commit is contained in:
parent
323f954ff1
commit
3bb589e12c
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<String>,
|
||||
/// The email of the co-author
|
||||
#[clap(long, required_unless_present("name"))]
|
||||
email: Option<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let opt = Opt::parse();
|
||||
let opt = cli::GitDeleteCoauthor::parse();
|
||||
|
||||
let mut authors = get_available_coauthors();
|
||||
|
||||
|
|
|
|||
|
|
@ -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<String>,
|
||||
/// A list of co-author initials
|
||||
coauthors: Vec<String>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args = Opt::parse();
|
||||
let args = cli::GitMob::parse();
|
||||
|
||||
if args.list {
|
||||
list_coauthors();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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<String>,
|
||||
/// A list of co-author initials
|
||||
pub coauthors: Vec<String>,
|
||||
}
|
||||
|
||||
#[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 {}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue