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

View File

@ -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();

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 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<String>,
/// A list of co-author initials
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()));
}
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<Author> {
fn select_coauthors(coauthor_initials: &[String]) -> Vec<Author> {
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 {
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 std::fs::File;
fn main() {
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 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<BTreeMap<String, Author>, Box<dyn Error>> {
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: FnOnce(Repository)>(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<String, Author>) {
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);