mirror of
https://codeberg.org/Cyborus/forgejo-cli.git
synced 2024-11-10 03:59:31 +01:00
feat: FJ_FALLBACK_HOST
an environment variable to define the host to use when none other is specified
This commit is contained in:
parent
e68408e321
commit
9eca2b516a
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) {
|
||||
(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()
|
||||
|
|
Loading…
Reference in a new issue