Rustfmt everything

This commit is contained in:
Martin Frost 2020-09-05 16:07:58 +02:00 committed by Martin Frost
parent a5ff50fd1b
commit 20997a0605
6 changed files with 42 additions and 41 deletions

View File

@ -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; use structopt::StructOpt;
#[derive(StructOpt,Debug)] #[derive(StructOpt, Debug)]
struct Opt { struct Opt {
/// Co-author initials /// Co-author initials
initials: String, initials: String,

View File

@ -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; use structopt::StructOpt;
#[derive(StructOpt,Debug)] #[derive(StructOpt, Debug)]
struct Opt { struct Opt {
/// Initials of the co-author to delete /// Initials of the co-author to delete
initials: String, initials: String,

View File

@ -1,8 +1,8 @@
use git_mob::{Author, get_available_coauthors, write_coauthors_file} ; use git_mob::{get_available_coauthors, write_coauthors_file, Author};
use structopt::StructOpt;
use std::process; use std::process;
use structopt::StructOpt;
#[derive(StructOpt,Debug)] #[derive(StructOpt, Debug)]
struct Opt { struct Opt {
/// Co-author initials /// Co-author initials
initials: String, initials: String,
@ -18,7 +18,7 @@ fn main() {
let opt = Opt::from_args(); let opt = Opt::from_args();
let mut authors = get_available_coauthors(); let mut authors = get_available_coauthors();
let mut updated_author : Author; let mut updated_author: Author;
if let Some(author) = authors.get(&opt.initials) { if let Some(author) = authors.get(&opt.initials) {
updated_author = author.clone(); updated_author = author.clone();

View File

@ -1,15 +1,18 @@
use git_mob::{Author, get_main_author, get_available_coauthors, with_gitmessage_template_path_or_exit, set_main_author}; use git_mob::{
use structopt::StructOpt; get_available_coauthors, get_main_author, set_main_author,
use std::process; with_gitmessage_template_path_or_exit, Author,
};
use std::fs; use std::fs;
use std::process;
use structopt::StructOpt;
#[derive(StructOpt,Debug)] #[derive(StructOpt, Debug)]
struct Opt { struct Opt {
/// Prints list of available co-authors /// Prints list of available co-authors
#[structopt(short,long)] #[structopt(short, long)]
list: bool, list: bool,
/// Overwrite the main author /// Overwrite the main author
#[structopt(short,long)] #[structopt(short, long)]
overwrite: Option<String>, overwrite: Option<String>,
/// A list of co-author initials /// A list of co-author initials
coauthors: Vec<String>, coauthors: Vec<String>,
@ -54,25 +57,23 @@ fn write_coauthors_to_gitmessage_file(coauthor_initials: &[String]) {
content.push_str(&format!("Co-authored-by: {}\n", &author.to_string())); content.push_str(&format!("Co-authored-by: {}\n", &author.to_string()));
} }
with_gitmessage_template_path_or_exit(|path| { with_gitmessage_template_path_or_exit(|path| match fs::write(path, content) {
match fs::write(path, content) { Ok(_) => {
Ok(_) => { println!("{}", get_main_author());
println!("{}", get_main_author()); for author in &coauthors {
for author in &coauthors { println!("{}", author);
println!("{}", author); }
} }
}, Err(e) => {
Err(e) => { eprintln!("Error writing to .gitmessage template: {}", e);
eprintln!("Error writing to .gitmessage template: {}", e); process::exit(1);
process::exit(1);
},
} }
}); });
} }
fn select_coauthors(coauthor_initials : &[String]) -> Vec<Author> { fn select_coauthors(coauthor_initials: &[String]) -> Vec<Author> {
let all_coauthors = get_available_coauthors(); let all_coauthors = get_available_coauthors();
let mut coauthors : Vec<Author> = Vec::new(); let mut coauthors: Vec<Author> = Vec::new();
for initial in coauthor_initials { for initial in coauthor_initials {
match all_coauthors.get(initial) { match all_coauthors.get(initial) {

View File

@ -1,5 +1,5 @@
use std::fs::File;
use git_mob::{get_main_author, with_gitmessage_template_path_or_exit}; use git_mob::{get_main_author, with_gitmessage_template_path_or_exit};
use std::fs::File;
fn main() { fn main() {
let main_author = get_main_author(); let main_author = get_main_author();

View File

@ -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 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::error::Error;
use std::string::String; use std::fs::File;
use std::io::BufReader;
use std::process; use std::process;
use std::string::String;
#[derive(Serialize, Deserialize, Clone, Debug)] #[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Author { pub struct Author {
@ -57,11 +57,11 @@ fn parse_coauthors_file() -> Result<BTreeMap<String, Author>, Box<dyn Error>> {
let coauthors_file = File::open(coauthors_path)?; let coauthors_file = File::open(coauthors_path)?;
let reader = BufReader::new(coauthors_file); 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") { match json_data.get("coauthors") {
Some(coauthors) => Ok(serde_json::from_value(coauthors.clone()).unwrap()), 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: FnOnce(Repository)>(f: F) {
match Repository::open_from_env() { match Repository::open_from_env() {
Ok(repo) => { Ok(repo) => {
f(repo); f(repo);
}, }
Err(_e) => { Err(_e) => {
eprintln!("Not in a git repository"); eprintln!("Not in a git repository");
process::exit(1); process::exit(1);
@ -89,7 +89,7 @@ pub fn write_coauthors_file(authors: BTreeMap<String, Author>) {
wrapper_tree.insert("coauthors", authors); wrapper_tree.insert("coauthors", authors);
let json_data = serde_json::to_string_pretty(&wrapper_tree).unwrap(); let json_data = serde_json::to_string_pretty(&wrapper_tree).unwrap();
match fs::write(coauthors_file_path(), json_data) { match fs::write(coauthors_file_path(), json_data) {
Ok(_) => {}, Ok(_) => {}
Err(e) => { Err(e) => {
eprintln!("Error writing git-coauthors file: {:?}", e); eprintln!("Error writing git-coauthors file: {:?}", e);
process::exit(1); process::exit(1);