From 9eca2b516af81b894493e25345ccd38f51caed76 Mon Sep 17 00:00:00 2001 From: Cyborus Date: Thu, 4 Jul 2024 18:15:03 -0400 Subject: [PATCH] feat: `FJ_FALLBACK_HOST` an environment variable to define the host to use when none other is specified --- src/repo.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 { + if let Some(envvar) = std::env::var_os("FJ_FALLBACK_HOST") { + let out = envvar.to_str().and_then(|x| x.parse::().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()