1use std::path::Path;
2use anyhow::Result;
3use apm_core::{config::Config, ticket::Ticket};
4
5pub struct CmdContext {
6 pub config: Config,
7 pub tickets: Vec<Ticket>,
8 pub aggressive: bool,
9}
10
11impl CmdContext {
12 pub fn load(root: &Path, no_aggressive: bool) -> Result<Self> {
13 let config = Config::load(root)?;
14 let aggressive = config.sync.aggressive && !no_aggressive;
15 crate::util::fetch_if_aggressive(root, aggressive);
16 let tickets = if aggressive {
17 apm_core::ticket::load_all_from_git_classified(root, &config.tickets.dir)?
18 } else {
19 apm_core::ticket::load_all_from_git(root, &config.tickets.dir)?
20 };
21 Ok(Self { config, tickets, aggressive })
22 }
23
24 pub fn load_config_only(root: &Path) -> Result<Config> {
25 Config::load(root)
26 }
27}