hive-forge: rewrite bash CLI helper as a rust binary (closes #280)

This commit is contained in:
damocles 2026-05-25 01:30:44 +02:00 committed by Mara
parent 560360d2e3
commit 595e3c040c
28 changed files with 1434 additions and 612 deletions

View file

@ -0,0 +1,34 @@
//! `branches [pattern] [repo]` — list branches, optionally filtered.
use anyhow::Result;
use clap::Args as ClapArgs;
use serde_json::Value;
use crate::client::Client;
#[derive(ClapArgs)]
pub struct Args {
/// Substring pattern to filter branch names.
pattern: Option<String>,
/// Repo override.
repo: Option<String>,
}
pub fn run(client: &Client, args: Args) -> Result<()> {
let repo = client.repo(args.repo.as_deref());
let v = client.get_json(&format!("/repos/{repo}/branches?limit=100"))?;
let names: Vec<&str> = v
.as_array()
.map(|a| {
a.iter()
.filter_map(|b| b.get("name").and_then(Value::as_str))
.collect()
})
.unwrap_or_default();
for n in names {
if args.pattern.as_deref().is_none_or(|p| n.contains(p)) {
println!("{n}");
}
}
Ok(())
}