diff --git a/src/bin/git-add-coauthor.rs b/src/bin/git-add-coauthor.rs index 2e5afb7..14d50a7 100644 --- a/src/bin/git-add-coauthor.rs +++ b/src/bin/git-add-coauthor.rs @@ -1,7 +1,7 @@ -use git_mob::{Author, get_available_coauthors, write_coauthors_file} ; +use git_mob::{get_available_coauthors, write_coauthors_file, Author}; use structopt::StructOpt; -#[derive(StructOpt,Debug)] +#[derive(StructOpt, Debug)] struct Opt { /// Co-author initials initials: String, diff --git a/src/bin/git-delete-coauthor.rs b/src/bin/git-delete-coauthor.rs index 4c8ef57..485621b 100644 --- a/src/bin/git-delete-coauthor.rs +++ b/src/bin/git-delete-coauthor.rs @@ -1,7 +1,7 @@ -use git_mob::{get_available_coauthors, write_coauthors_file} ; +use git_mob::{get_available_coauthors, write_coauthors_file}; use structopt::StructOpt; -#[derive(StructOpt,Debug)] +#[derive(StructOpt, Debug)] struct Opt { /// Initials of the co-author to delete initials: String, diff --git a/src/bin/git-edit-coauthor.rs b/src/bin/git-edit-coauthor.rs index 6961e9d..57044df 100644 --- a/src/bin/git-edit-coauthor.rs +++ b/src/bin/git-edit-coauthor.rs @@ -1,8 +1,8 @@ -use git_mob::{Author, get_available_coauthors, write_coauthors_file} ; -use structopt::StructOpt; +use git_mob::{get_available_coauthors, write_coauthors_file, Author}; use std::process; +use structopt::StructOpt; -#[derive(StructOpt,Debug)] +#[derive(StructOpt, Debug)] struct Opt { /// Co-author initials initials: String, @@ -18,7 +18,7 @@ fn main() { let opt = Opt::from_args(); let mut authors = get_available_coauthors(); - let mut updated_author : Author; + let mut updated_author: Author; if let Some(author) = authors.get(&opt.initials) { updated_author = author.clone(); diff --git a/src/bin/git-mob.rs b/src/bin/git-mob.rs index 2122eb2..070d6e9 100644 --- a/src/bin/git-mob.rs +++ b/src/bin/git-mob.rs @@ -1,15 +1,18 @@ -use git_mob::{Author, get_main_author, get_available_coauthors, with_gitmessage_template_path_or_exit, set_main_author}; -use structopt::StructOpt; -use std::process; +use git_mob::{ + get_available_coauthors, get_main_author, set_main_author, + with_gitmessage_template_path_or_exit, Author, +}; use std::fs; +use std::process; +use structopt::StructOpt; -#[derive(StructOpt,Debug)] +#[derive(StructOpt, Debug)] struct Opt { /// Prints list of available co-authors - #[structopt(short,long)] + #[structopt(short, long)] list: bool, /// Overwrite the main author - #[structopt(short,long)] + #[structopt(short, long)] overwrite: Option, /// A list of co-author initials coauthors: Vec, @@ -54,25 +57,23 @@ fn write_coauthors_to_gitmessage_file(coauthor_initials: &[String]) { content.push_str(&format!("Co-authored-by: {}\n", &author.to_string())); } - with_gitmessage_template_path_or_exit(|path| { - match fs::write(path, content) { - Ok(_) => { - println!("{}", get_main_author()); - for author in &coauthors { - println!("{}", author); - } - }, - Err(e) => { - eprintln!("Error writing to .gitmessage template: {}", e); - process::exit(1); - }, + with_gitmessage_template_path_or_exit(|path| match fs::write(path, content) { + Ok(_) => { + println!("{}", get_main_author()); + for author in &coauthors { + println!("{}", author); + } + } + Err(e) => { + eprintln!("Error writing to .gitmessage template: {}", e); + process::exit(1); } }); } -fn select_coauthors(coauthor_initials : &[String]) -> Vec { +fn select_coauthors(coauthor_initials: &[String]) -> Vec { let all_coauthors = get_available_coauthors(); - let mut coauthors : Vec = Vec::new(); + let mut coauthors: Vec = Vec::new(); for initial in coauthor_initials { match all_coauthors.get(initial) { diff --git a/src/bin/git-solo.rs b/src/bin/git-solo.rs index 2f4b318..e2315d8 100644 --- a/src/bin/git-solo.rs +++ b/src/bin/git-solo.rs @@ -1,5 +1,5 @@ -use std::fs::File; use git_mob::{get_main_author, with_gitmessage_template_path_or_exit}; +use std::fs::File; fn main() { let main_author = get_main_author(); diff --git a/src/lib.rs b/src/lib.rs index bfeecb2..9343779 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,15 @@ -use serde::{Deserialize, Serialize}; -use std::fs; -use git2::{Config, Repository}; -use std::fmt; -use std::collections::BTreeMap; use dirs::home_dir; +use git2::{Config, Repository}; +use serde::{Deserialize, Serialize}; +use std::collections::BTreeMap; +use std::fmt; +use std::fs; -use std::io::BufReader; -use std::fs::File; use std::error::Error; -use std::string::String; +use std::fs::File; +use std::io::BufReader; use std::process; +use std::string::String; #[derive(Serialize, Deserialize, Clone, Debug)] pub struct Author { @@ -57,11 +57,11 @@ fn parse_coauthors_file() -> Result, Box> { let coauthors_file = File::open(coauthors_path)?; let reader = BufReader::new(coauthors_file); - let json_data : serde_json::Value = serde_json::from_reader(reader)?; + let json_data: serde_json::Value = serde_json::from_reader(reader)?; match json_data.get("coauthors") { Some(coauthors) => Ok(serde_json::from_value(coauthors.clone()).unwrap()), - None => Ok(BTreeMap::new()) + None => Ok(BTreeMap::new()), } } @@ -69,7 +69,7 @@ fn with_git_repo_or_exit(f: F) { match Repository::open_from_env() { Ok(repo) => { f(repo); - }, + } Err(_e) => { eprintln!("Not in a git repository"); process::exit(1); @@ -89,7 +89,7 @@ pub fn write_coauthors_file(authors: BTreeMap) { wrapper_tree.insert("coauthors", authors); let json_data = serde_json::to_string_pretty(&wrapper_tree).unwrap(); match fs::write(coauthors_file_path(), json_data) { - Ok(_) => {}, + Ok(_) => {} Err(e) => { eprintln!("Error writing git-coauthors file: {:?}", e); process::exit(1);