Get rid of Backend::Unknown variant

This commit is contained in:
southerntofu 2022-01-09 16:29:23 +01:00
parent ad61faaecf
commit dbd65cdc27
2 changed files with 15 additions and 36 deletions

View File

@ -6,16 +6,18 @@ use std::process::Command;
pub enum Backend {
Git,
Mercurial,
Unknown(String),
}
impl Backend {
pub fn from_setting(setting: Option<String>) -> Backend {
/// Generates Some(Backend) from an optional String, or defaults to Git,
/// or None when the backend is not recognized
/// TODO: fallback backend should be customizable
pub fn from_setting(setting: Option<String>) -> Option<Backend> {
// Git is the default setting until further notice
setting.map_or(Backend::Git, |name| match name.as_ref() {
"git" => Backend::Git,
"mercurial" => Backend::Mercurial,
_ => Backend::Unknown(name.to_string()),
setting.map_or(Some(Backend::Git), |name| match name.as_ref() {
"git" => Some(Backend::Git),
"mercurial" => Some(Backend::Mercurial),
_ => None,
})
}
}
@ -55,10 +57,6 @@ impl Repo {
Backend::Mercurial => {
unreachable!("UNIMPLEMENTED!");
}
Backend::Unknown(name) => {
// TODO: This should be a forgebuild error message
panic!("Uknown backend: {}. Cannot find branch", name);
}
}
}
@ -77,11 +75,6 @@ impl Repo {
Backend::Mercurial => {
unreachable!("Unimplemented");
}
Backend::Unknown(name) => {
// TODO: This should be a forgebuild error message
eprintln!("Unknown DVCS: {}", name);
false
}
};
// If the clone was successful and subupdates is enabled,
@ -124,11 +117,6 @@ impl Repo {
Backend::Mercurial => {
unreachable!("UNIMPLEMENTED");
}
Backend::Unknown(name) => {
// TODO: This should be a forgebuild error message
eprintln!("Unknown DVCS: {}", name);
false
}
}
}
@ -160,11 +148,6 @@ impl Repo {
},
Backend::Mercurial => {
unimplemented!("Soon");
},
Backend::Unknown(name) => {
// TODO: This should be a forgebuild error message
eprintln!("Unknown DVCS:{}!", name);
Vec::new()
}
}
}
@ -205,11 +188,6 @@ impl Repo {
Backend::Mercurial => {
unimplemented!();
},
Backend::Unknown(name) => {
// TODO: This should be a forgebuild error message
eprintln!("Unknown DVCS:{}!", name);
false
}
}
}
@ -259,11 +237,6 @@ impl Repo {
Backend::Mercurial => {
unreachable!("unimplemented");
}
Backend::Unknown(name) => {
// TODO: This should be a forgebuild error message
eprintln!("Unknown DVCS:{}!", name);
false
}
}
}
}

View File

@ -76,13 +76,19 @@ impl Task {
context.insert("$i18n_source".to_string(), source_url.clone());
}
let dvcs = if let Some(dvcs) = Backend::from_setting(read_extension(path, "dvcs")) { dvcs } else {
// TODO: forgebuild error message
eprintln!("Unrecognized dvcs for task {}, possible options are 'git' or 'mercurial'. Skipped", &name);
return None;
};
Some(Task {
name,
bin: path.to_path_buf(),
// None source = None repo
repo: source.as_ref().map(|s| {
Repo::new(
Backend::from_setting(read_extension(path, "dvcs")),
dvcs,
s,
&dest,
subupdates,