diff --git a/src/onefetch/cli.rs b/src/onefetch/cli.rs index a985d63cc..2f65c64b0 100644 --- a/src/onefetch/cli.rs +++ b/src/onefetch/cli.rs @@ -39,6 +39,7 @@ pub struct Cli { pub art_off: bool, pub text_colors: Vec, pub iso_time: bool, + pub show_email: bool, } impl Cli { @@ -259,6 +260,12 @@ impl Cli { .map_err(|e| e.to_string()) }) ) + .arg( + Arg::with_name("show-email") + .short("E") + .long("show-email") + .help("show the email address of each author.") + ) .arg( Arg::with_name("exclude") .short("e") @@ -282,6 +289,7 @@ impl Cli { let print_languages = matches.is_present("languages"); let print_package_managers = matches.is_present("package-managers"); let iso_time = matches.is_present("isotime"); + let show_email = matches.is_present("show-email"); let output = matches.value_of("output").map(SerializationFormat::from_str).transpose().unwrap(); @@ -392,6 +400,7 @@ impl Cli { text_colors, art_off, iso_time, + show_email, }) } } diff --git a/src/onefetch/info.rs b/src/onefetch/info.rs index 7aabbf9ab..6865dadb8 100644 --- a/src/onefetch/info.rs +++ b/src/onefetch/info.rs @@ -21,7 +21,7 @@ pub struct Info { creation_date: String, languages: Vec<(Language, f64)>, dependencies: String, - authors: Vec<(String, usize, usize)>, + authors: Vec<(String, Option, usize, usize)>, last_change: String, repo_url: String, number_of_commits: String, @@ -221,7 +221,7 @@ impl Info { let number_of_branches = internal_repo.get_number_of_branches()?; let creation_date = internal_repo.get_creation_date(config.iso_time)?; let number_of_commits = internal_repo.get_number_of_commits(); - let authors = internal_repo.get_authors(config.number_of_authors); + let authors = internal_repo.get_authors(config.number_of_authors, config.show_email); let last_change = internal_repo.get_date_of_last_commit(config.iso_time); let (repo_size, file_count) = internal_repo.get_repo_size(); let workdir = internal_repo.get_work_dir()?; @@ -312,15 +312,21 @@ impl Info { let pad = title.len() + 2; - for (i, (author_name, author_nbr_commits, autor_contribution)) in + for (i, (author_name, author_email_opt, author_nbr_commits, autor_contribution)) in self.authors.iter().enumerate() { + let author = if let Some(author_email) = author_email_opt { + format!("{} <{}>", author_name, author_email) + } else { + author_name.to_owned() + }; + if i == 0 { author_field.push_str(&format!( "{}{} {} {}\n", autor_contribution.to_string().color(self.text_colors.info), "%".color(self.text_colors.info), - author_name.to_string().color(self.text_colors.info), + author.to_string().color(self.text_colors.info), author_nbr_commits.to_string().color(self.text_colors.info), )); } else { @@ -329,7 +335,7 @@ impl Info { "", autor_contribution.to_string().color(self.text_colors.info), "%".color(self.text_colors.info), - author_name.to_string().color(self.text_colors.info), + author.to_string().color(self.text_colors.info), author_nbr_commits.to_string().color(self.text_colors.info), width = pad )); diff --git a/src/onefetch/repo.rs b/src/onefetch/repo.rs index a343ce04e..11ab4321e 100644 --- a/src/onefetch/repo.rs +++ b/src/onefetch/repo.rs @@ -63,7 +63,11 @@ impl<'a> Repo<'a> { number_of_commits.to_string() } - pub fn get_authors(&self, n: usize) -> Vec<(String, usize, usize)> { + pub fn get_authors( + &self, + n: usize, + show_email: bool, + ) -> Vec<(String, Option, usize, usize)> { let mut authors = std::collections::HashMap::new(); let mut author_name_by_email = std::collections::HashMap::new(); let mut total_nbr_of_commits = 0; @@ -83,11 +87,12 @@ impl<'a> Repo<'a> { authors.truncate(n); - let authors: Vec<(String, usize, usize)> = authors + let authors: Vec<(String, Option, usize, usize)> = authors .into_iter() .map(|(author_email, author_nbr_of_commits)| { ( author_name_by_email.get(&author_email).unwrap().trim_matches('\'').to_string(), + show_email.then(|| author_email), author_nbr_of_commits, (author_nbr_of_commits as f32 * 100. / total_nbr_of_commits as f32).round() as usize,