35 lines
908 B
Rust
35 lines
908 B
Rust
//! `branches [pattern] [repo]` — list branches, optionally filtered.
|
|
|
|
use anyhow::{Result, bail};
|
|
use clap::Args as ClapArgs;
|
|
|
|
use crate::client::Client;
|
|
|
|
#[derive(ClapArgs)]
|
|
pub struct Args {
|
|
/// Substring pattern to filter branch names.
|
|
pattern: Option<String>,
|
|
}
|
|
|
|
pub fn run(client: &Client, args: Args) -> Result<()> {
|
|
if client.json_mode() {
|
|
bail!(
|
|
"hive-forge branches: --json is not supported for this verb, only the plain name list"
|
|
);
|
|
}
|
|
let (owner, name) = client.owner_repo()?;
|
|
let (_, branches) = client
|
|
.api()
|
|
.repo_list_branches(owner, name)
|
|
.page_size(100)
|
|
.send()?;
|
|
for branch in &branches {
|
|
let Some(n) = branch.name.as_deref() else {
|
|
continue;
|
|
};
|
|
if args.pattern.as_deref().is_none_or(|p| n.contains(p)) {
|
|
println!("{n}");
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|