//! `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, } pub fn run(client: &Client, args: Args) -> Result<()> { let repo = client.repo(); 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(()) }