use anyhow::Result;
use apm_core::config::resolve_identity;
use std::path::Path;
use crate::ctx::CmdContext;
pub fn run(root: &Path, state_filter: Option<String>, unassigned: bool, all: bool, actionable_filter: Option<String>, no_aggressive: bool, mine: bool, author: Option<String>, owner: Option<String>) -> Result<()> {
let ctx = CmdContext::load(root, no_aggressive)?;
let mine_user: Option<String> = if mine {
Some(resolve_identity(root))
} else {
None
};
let author_filter = if mine { None } else { author };
let filtered = apm_core::ticket::list_filtered(
&ctx.tickets,
&ctx.config,
state_filter.as_deref(),
unassigned,
all,
actionable_filter.as_deref(),
author_filter.as_deref(),
owner.as_deref(),
mine_user.as_deref(),
);
for t in filtered {
let fm = &t.frontmatter;
let owner = fm.owner.as_deref().unwrap_or("-");
let base = match fm.target_branch.as_deref() {
Some(branch) => apm_core::epic::epic_id_from_branch(branch).to_owned(),
None => ctx.config.project.default_branch.clone(),
};
println!("{:<8} [{:<12}] {:<16} {:<12} {}", fm.id, fm.state, owner, base, fm.title);
}
Ok(())
}