hive-forge: global -r/--repo flag instead of per-verb [repo] positional (mara@#407)

This commit is contained in:
damocles 2026-05-25 02:12:04 +02:00 committed by Mara
commit badf21714b
21 changed files with 46 additions and 85 deletions

View file

@ -30,10 +30,14 @@ pub struct Client {
impl Client {
/// Build a client from the standard environment variables.
pub fn from_env() -> Result<Self> {
/// `repo_override` (from the global `-r/--repo` flag) takes
/// priority over `HIVE_FORGE_REPO`; the env var is the fallback
/// default.
pub fn from_env(repo_override: Option<String>) -> Result<Self> {
let base = std::env::var("HIVE_FORGE_URL").unwrap_or_else(|_| DEFAULT_URL.to_owned());
let default_repo =
std::env::var("HIVE_FORGE_REPO").unwrap_or_else(|_| DEFAULT_REPO.to_owned());
let default_repo = repo_override
.or_else(|| std::env::var("HIVE_FORGE_REPO").ok())
.unwrap_or_else(|| DEFAULT_REPO.to_owned());
let token = read_token().context("read forge-token")?;
let mut headers = HeaderMap::new();
@ -59,9 +63,11 @@ impl Client {
format!("{}/api/v1", self.base)
}
/// Pick the user-supplied repo or fall back to the default.
pub fn repo<'a>(&'a self, override_: Option<&'a str>) -> &'a str {
override_.unwrap_or(&self.default_repo)
/// Return the active repo. `from_env` already folded the
/// `-r/--repo` override into `default_repo`, so verbs just read
/// it as-is — no per-verb override plumbing.
pub fn repo(&self) -> &str {
&self.default_repo
}
/// GET `<api>/<path>` and decode JSON.