feat: FJ_FALLBACK_HOST

an environment variable to define the host to use when none other is
specified
This commit is contained in:
Cyborus 2024-07-04 18:15:03 -04:00
parent e68408e321
commit 9eca2b516a
No known key found for this signature in database

View file

@ -173,6 +173,8 @@ impl RepoInfo {
}
};
let url = url.or_else(fallback_host);
let info = match (url, name) {
(Some(url), name) => RepoInfo { url, name },
(None, Some(_)) => eyre::bail!("cannot find repo, no host specified"),
@ -191,6 +193,18 @@ impl RepoInfo {
}
}
fn fallback_host() -> Option<Url> {
if let Some(envvar) = std::env::var_os("FJ_FALLBACK_HOST") {
let out = envvar.to_str().and_then(|x| x.parse::<Url>().ok());
if out.is_none() {
println!("warn: `FJ_FALLBACK_HOST` is not set to a valid url");
}
out
} else {
None
}
}
fn url_strip_repo_name(mut url: Url) -> eyre::Result<(Url, RepoName)> {
let mut iter = url
.path_segments()