diff options
author | Cyborus <cyborus@noreply.codeberg.org> | 2024-07-05 04:38:27 +0200 |
---|---|---|
committer | Cyborus <cyborus@noreply.codeberg.org> | 2024-07-05 04:38:27 +0200 |
commit | 02e27479fc08c2b598cad414515dfaec7127866b (patch) | |
tree | a521ef11f5bdf450a2b1f1d0b72ae51f938e8dce | |
parent | Merge pull request 'enable update checking in CI builds' (#81) from deploy-fe... (diff) | |
parent | feat: `FJ_FALLBACK_HOST` (diff) | |
download | forgejo-cli-02e27479fc08c2b598cad414515dfaec7127866b.tar.xz forgejo-cli-02e27479fc08c2b598cad414515dfaec7127866b.zip |
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
-rw-r--r-- | src/repo.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/repo.rs b/src/repo.rs index e97ecb4..f0c6a90 100644 --- a/src/repo.rs +++ b/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() |