mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 12:09:33 +01:00
Merge pull request 'add FJ_FALLBACK_HOST
env var' (#82) from host-fallback into main
Reviewed-on: https://codeberg.org/Cyborus/forgejo-cli/pulls/82
This commit is contained in:
commit
02e27479fc
1 changed files with 14 additions and 0 deletions
14
src/repo.rs
14
src/repo.rs
|
@ -173,6 +173,8 @@ impl RepoInfo {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let url = url.or_else(fallback_host);
|
||||||
|
|
||||||
let info = match (url, name) {
|
let info = match (url, name) {
|
||||||
(Some(url), name) => RepoInfo { url, name },
|
(Some(url), name) => RepoInfo { url, name },
|
||||||
(None, Some(_)) => eyre::bail!("cannot find repo, no host specified"),
|
(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)> {
|
fn url_strip_repo_name(mut url: Url) -> eyre::Result<(Url, RepoName)> {
|
||||||
let mut iter = url
|
let mut iter = url
|
||||||
.path_segments()
|
.path_segments()
|
||||||
|
|
Loading…
Reference in a new issue