From 609cdf83d86529e7c2a1c761659179d43366cdcd Mon Sep 17 00:00:00 2001 From: Martin Frost Date: Sun, 24 May 2020 13:13:30 +0200 Subject: [PATCH] Add git-edit-coauthor command It is now possible to edit the available co-authors, in case you misspelled someone's name, or they change their email address, or something. --- Cargo.lock | 2 +- Cargo.toml | 2 +- README.md | 8 +++++-- src/bin/git-edit-coauthor.rs | 41 ++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/bin/git-edit-coauthor.rs diff --git a/Cargo.lock b/Cargo.lock index 93bf953..c3aaa2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -158,7 +158,7 @@ dependencies = [ [[package]] name = "git_mob" -version = "0.1.0" +version = "0.2.0" dependencies = [ "dirs", "git2", diff --git a/Cargo.toml b/Cargo.toml index e81fe1b..df463f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "git_mob" -version = "0.1.0" +version = "0.2.0" authors = ["Martin Frost "] edition = "2018" description = "A CLI tool for social coding." diff --git a/README.md b/README.md index d7efa8a..88d39d6 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ It is essentially a Rust clone of the [git-mob NPM package](https://www.npmjs.co * Add Alice and Bob as a possible co-authors: git add-coauthor a "Alice" alice@example.com - git add-coauthor b "Bob" bob@example.com + git add-coauthor b "bob" Bob@example.com * Set Alice as co-author, making your mob consist of you and Alice: @@ -24,6 +24,10 @@ It is essentially a Rust clone of the [git-mob NPM package](https://www.npmjs.co git mob a b +* Edit Bob's name, since you accidentally capitalized his email instead of his name: + + git edit-coauthor b --name "Bob" --email bob@example.com + * Remove Bob as a possible co-author: git delete-coauthor b @@ -41,6 +45,7 @@ It is essentially a Rust clone of the [git-mob NPM package](https://www.npmjs.co * `git mob ` * `git add-coauthor "Co-author Name" ` +* `git edit-coauthor [--name "Co-author Name"] [--email ]` * `git delete-coauthor ` * `git mob -l` * `git solo` @@ -55,7 +60,6 @@ be implemented, and then there is also a severe lack of tests and documentation. ### Missing features * `git mob-print` -* `git edit-coauthor` * `git suggest-coauthors` * `-o` for overwriting the main author * `--installTemplate` and `--uninstallTemplate` for prepare-commit-msg diff --git a/src/bin/git-edit-coauthor.rs b/src/bin/git-edit-coauthor.rs new file mode 100644 index 0000000..6961e9d --- /dev/null +++ b/src/bin/git-edit-coauthor.rs @@ -0,0 +1,41 @@ +use git_mob::{Author, get_available_coauthors, write_coauthors_file} ; +use structopt::StructOpt; +use std::process; + +#[derive(StructOpt,Debug)] +struct Opt { + /// Co-author initials + initials: String, + /// The name of the co-author, in quotes, e.g. "Foo Bar" + #[structopt(long, required_unless("email"))] + name: Option, + /// The email of the co-author + #[structopt(long, required_unless("name"))] + email: Option, +} + +fn main() { + let opt = Opt::from_args(); + + let mut authors = get_available_coauthors(); + let mut updated_author : Author; + + if let Some(author) = authors.get(&opt.initials) { + updated_author = author.clone(); + } else { + eprintln!("No author found with initials {}", &opt.initials); + process::exit(1); + } + + if let Some(name) = opt.name { + updated_author.name = name; + } + + if let Some(email) = opt.email { + updated_author.email = email; + } + + authors.insert(opt.initials, updated_author); + + write_coauthors_file(authors); +}