Skip to main content

apm/cmd/
archive.rs

1use anyhow::Result;
2use apm_core::{archive, clean, config::Config};
3use std::path::Path;
4
5pub fn run(root: &Path, dry_run: bool, older_than: Option<String>) -> Result<()> {
6    let config = Config::load(root)?;
7
8    let threshold = older_than
9        .as_deref()
10        .map(clean::parse_older_than)
11        .transpose()?;
12
13    let out = archive::archive(root, &config, dry_run, threshold)?;
14
15    for w in &out.warnings {
16        eprintln!("{w}");
17    }
18    for (old, new) in &out.dry_run_moves {
19        println!("{old} -> {new}");
20    }
21    // Original behavior: in dry_run, "nothing to archive" is always printed
22    // (because the moves vec was always empty in the original dry_run path).
23    if dry_run || out.archived_count == 0 {
24        println!("nothing to archive");
25    } else {
26        println!("archived {} ticket(s)", out.archived_count);
27    }
28
29    Ok(())
30}