30 lines
741 B
Rust
30 lines
741 B
Rust
//! `branches [pattern] [repo]` — list branches, optionally filtered.
|
|
|
|
use anyhow::Result;
|
|
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<()> {
|
|
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(())
|
|
}
|