Tidy up write_coauthors_to_gitmessage_file
* Inline closure * Do some actual error handling
This commit is contained in:
parent
e64c6d7b74
commit
934405ad4b
|
|
@ -30,27 +30,29 @@ fn list_coauthors() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write_coauthors_to_gitmessage_file(coauthor_initials: &Vec<String>) {
|
fn write_coauthors_to_gitmessage_file(coauthor_initials: &[String]) {
|
||||||
let coauthors = select_coauthors(&coauthor_initials);
|
let coauthors = select_coauthors(&coauthor_initials);
|
||||||
let mut content = String::from("\n\n");
|
let mut content = String::from("\n\n");
|
||||||
for author in &coauthors {
|
for author in &coauthors {
|
||||||
content.push_str(&format!("Co-authored-by: {}\n", &author.to_string()));
|
content.push_str(&format!("Co-authored-by: {}\n", &author.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let write_stuff = |repo: Repository| {
|
with_repo_or_exit(|repo: Repository| {
|
||||||
let path = gitmessage_template_file_path(repo);
|
let path = gitmessage_template_file_path(repo);
|
||||||
|
|
||||||
match fs::write(path, content) {
|
match fs::write(path, content) {
|
||||||
Ok(_) => {},
|
Ok(_) => {
|
||||||
Err(_e) => {},
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
with_repo_or_exit(write_stuff);
|
|
||||||
println!("{}", get_main_author());
|
println!("{}", get_main_author());
|
||||||
for author in &coauthors {
|
for author in &coauthors {
|
||||||
println!("{}", author);
|
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> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue