Don't add repo if it's already tracked
This commit is contained in:
parent
cab4deca11
commit
a2f86770d1
|
@ -13,7 +13,7 @@ pub struct Config {
|
||||||
pub repositories: Vec<Repository>,
|
pub repositories: Vec<Repository>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||||
/// The internal representation of a single repository
|
/// The internal representation of a single repository
|
||||||
pub struct Repository {
|
pub struct Repository {
|
||||||
name: String,
|
name: String,
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -116,11 +116,17 @@ pub fn run(state: State, mut config: Config) -> Result<(), Box<dyn Error>> {
|
||||||
println!("{}", config.to_string().unwrap());
|
println!("{}", config.to_string().unwrap());
|
||||||
}
|
}
|
||||||
Some(Cmd::Add) => {
|
Some(Cmd::Add) => {
|
||||||
config.repositories.push(Repository::new(match state.url {
|
let repo = Repository::new(match state.url {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
}));
|
});
|
||||||
config.save_config()?;
|
if let None = config.repositories.iter().find(|x| **x == repo) {
|
||||||
|
config.repositories.push(repo);
|
||||||
|
config.save_config()?;
|
||||||
|
println!("Repository has been added");
|
||||||
|
} else {
|
||||||
|
println!("Repository is already being tracked");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
println!("{:?} hasn't been implemented yet!", x)
|
println!("{:?} hasn't been implemented yet!", x)
|
||||||
|
|
Loading…
Reference in New Issue