From 9be6f97a5e4d5872069567c932f9ce8cef7bc755 Mon Sep 17 00:00:00 2001 From: Martin Frost Date: Fri, 20 Aug 2021 22:43:05 +0200 Subject: [PATCH] Stop printing on stderr when adding first coauthor Before this change, when running `git add-coauthor` without an existing `~/.git-coauthors` file, the program would print an error message on stderr that the file did not exist. It would then create the file with the newly added co-author in it. That message seemed unnecessary and so it has now been removed. Co-authored-by: Maria Hansson --- src/bin/git-add-coauthor.rs | 5 +++-- src/lib.rs | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/git-add-coauthor.rs b/src/bin/git-add-coauthor.rs index 14d50a7..a31edfb 100644 --- a/src/bin/git-add-coauthor.rs +++ b/src/bin/git-add-coauthor.rs @@ -1,4 +1,4 @@ -use git_mob::{get_available_coauthors, write_coauthors_file, Author}; +use git_mob::{parse_coauthors_file, write_coauthors_file, Author}; use structopt::StructOpt; #[derive(StructOpt, Debug)] @@ -13,11 +13,12 @@ struct Opt { fn main() { let opt = Opt::from_args(); - let mut authors = get_available_coauthors(); + let mut authors = parse_coauthors_file().unwrap_or_default(); let new_author = Author { name: opt.name, email: opt.email, }; + authors.insert(opt.initials, new_author); write_coauthors_file(authors); diff --git a/src/lib.rs b/src/lib.rs index e3882a4..ba05dc4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -65,7 +65,7 @@ pub fn get_available_coauthors() -> BTreeMap { } } -fn parse_coauthors_file() -> Result, Box> { +pub fn parse_coauthors_file() -> Result, Box> { let coauthors_path = coauthors_file_path(); let coauthors_file = File::open(coauthors_path)?; let reader = BufReader::new(coauthors_file);