-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
64 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,20 +15,20 @@ struct Cli { | |
} | ||
|
||
trait Add { | ||
fn add(&self, initials: String, name: String, email: String) -> String; | ||
fn add(&self, initials: &str, name: &str, email: &str) -> String; | ||
} | ||
|
||
impl<T: FileActions, U: ExitWithError> Add for GitMob<T, U> { | ||
fn add(&self, initials: String, name: String, email: String) -> String { | ||
fn add(&self, initials: &str, name: &str, email: &str) -> String { | ||
let coauthors_path = self.get_coauthors_path(); | ||
let coauthors_path = coauthors_path.display(); | ||
|
||
let mut coauthors = self.get_all_coauthors(); | ||
coauthors.insert( | ||
initials, | ||
initials.to_string(), | ||
Author { | ||
name: name.clone(), | ||
email, | ||
name: name.to_string(), | ||
email: email.to_string(), | ||
}, | ||
); | ||
|
||
|
@@ -43,7 +43,7 @@ fn main() { | |
|
||
let gm = GitMob::default(); | ||
|
||
println!("{}", gm.add(opts.initials, opts.name, opts.email)); | ||
println!("{}", gm.add(&opts.initials, &opts.name, &opts.email)); | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -73,11 +73,7 @@ mod test { | |
"A B has been added to the {} file", | ||
coauthors_path.display() | ||
), | ||
gm.add( | ||
String::from("ab"), | ||
String::from("A B"), | ||
String::from("[email protected]"), | ||
) | ||
gm.add(&"ab", &"A B", &"[email protected]") | ||
); | ||
assert_eq!(expected_coauthors, gm.get_all_coauthors()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,15 @@ struct Cli { | |
} | ||
|
||
trait Edit { | ||
fn edit(&self, initials: String, name: Option<String>, email: Option<String>) -> String; | ||
fn edit(&self, initials: &str, name: Option<String>, email: Option<String>) -> String; | ||
} | ||
|
||
impl<T: FileActions, U: ExitWithError> Edit for GitMob<T, U> { | ||
fn edit(&self, initials: String, name: Option<String>, email: Option<String>) -> String { | ||
fn edit(&self, initials: &str, name: Option<String>, email: Option<String>) -> String { | ||
let coauthors_path = self.get_coauthors_path(); | ||
|
||
let mut coauthors = self.get_all_coauthors(); | ||
let coauthor = coauthors.get_mut(&initials); | ||
let coauthor = coauthors.get_mut(initials); | ||
match coauthor { | ||
Some(coauthor) => { | ||
if let Some(name) = name { | ||
|
@@ -36,7 +36,7 @@ impl<T: FileActions, U: ExitWithError> Edit for GitMob<T, U> { | |
} | ||
} | ||
None => { | ||
self.exit_with_error.message(format!( | ||
self.exit_with_error.message(&format!( | ||
"Author with initials \"{}\" not found in \"{}\"!", | ||
initials, | ||
coauthors_path.display() | ||
|
@@ -55,7 +55,7 @@ fn main() { | |
|
||
let gm = GitMob::default(); | ||
|
||
println!("{}", gm.edit(opts.initials, opts.name, opts.email)); | ||
println!("{}", gm.edit(&opts.initials, opts.name, opts.email)); | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -83,7 +83,7 @@ mod test { | |
}); | ||
|
||
gm.file_actions | ||
.write(&gm.get_coauthors_path(), coauthors.to_string()) | ||
.write(&gm.get_coauthors_path(), &coauthors.to_string()) | ||
.unwrap(); | ||
|
||
let mut expected_coauthors = LinkedHashMap::new(); | ||
|
@@ -105,7 +105,7 @@ mod test { | |
assert_eq!( | ||
"ab has been updated", | ||
gm.edit( | ||
String::from("ab"), | ||
&String::from("ab"), | ||
Some(String::from("C D")), | ||
Some(String::from("[email protected]")), | ||
) | ||
|
@@ -127,7 +127,7 @@ mod test { | |
}); | ||
|
||
gm.file_actions | ||
.write(&gm.get_coauthors_path(), coauthors.to_string()) | ||
.write(&gm.get_coauthors_path(), &coauthors.to_string()) | ||
.unwrap(); | ||
|
||
let mut expected_coauthors = LinkedHashMap::new(); | ||
|
@@ -141,7 +141,7 @@ mod test { | |
|
||
assert_eq!( | ||
"ab has been updated", | ||
gm.edit(String::from("ab"), Some(String::from("C D")), None) | ||
gm.edit(&String::from("ab"), Some(String::from("C D")), None) | ||
); | ||
assert_eq!(expected_coauthors, gm.get_all_coauthors()); | ||
} | ||
|
@@ -160,7 +160,7 @@ mod test { | |
}); | ||
|
||
gm.file_actions | ||
.write(&gm.get_coauthors_path(), coauthors.to_string()) | ||
.write(&gm.get_coauthors_path(), &coauthors.to_string()) | ||
.unwrap(); | ||
|
||
let mut expected_coauthors = LinkedHashMap::new(); | ||
|
@@ -175,7 +175,7 @@ mod test { | |
assert_eq!( | ||
"ab has been updated", | ||
gm.edit( | ||
String::from("ab"), | ||
&String::from("ab"), | ||
None, | ||
Some(String::from("[email protected]")) | ||
) | ||
|
@@ -187,6 +187,6 @@ mod test { | |
#[should_panic] | ||
fn test_edit_author_who_does_not_exist() { | ||
let gm = get_git_mob(); | ||
gm.edit(String::from("ef"), None, None); | ||
gm.edit(&String::from("ef"), None, None); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ mod test { | |
let authors = | ||
"\n\nCo-authored-by: A B <[email protected]>\nCo-authored-by: C D <[email protected]>\n"; | ||
|
||
gm.write_gitmessage(vec![String::from("ab"), String::from("cd")]); | ||
gm.write_gitmessage(&[String::from("ab"), String::from("cd")]); | ||
|
||
assert_eq!(authors, gm.print()); | ||
} | ||
|
@@ -58,11 +58,11 @@ mod test { | |
fn test_print_initials() { | ||
let gm = get_git_mob(); | ||
|
||
gm.write_gitmessage(vec![]); | ||
gm.write_gitmessage(&[]); | ||
|
||
assert_eq!("\n", gm.print_initials()); | ||
|
||
gm.write_gitmessage(vec![String::from("ab"), String::from("cd")]); | ||
gm.write_gitmessage(&[String::from("ab"), String::from("cd")]); | ||
|
||
assert_eq!("ab,cd\n", gm.print_initials()); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
use std::process::exit; | ||
|
||
pub trait ExitWithError { | ||
fn message<S: AsRef<str>>(&self, message: S) -> !; | ||
fn message(&self, message: &str) -> !; | ||
} | ||
|
||
pub struct ExitWithErrorImpl(); | ||
|
||
impl ExitWithError for ExitWithErrorImpl { | ||
fn message<S: AsRef<str>>(&self, message: S) -> ! { | ||
println!("{}", message.as_ref()); | ||
fn message(&self, message: &str) -> ! { | ||
println!("{}", message); | ||
exit(1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.