orbiton/commands/
maintenance.rs1use clap::{Parser, Subcommand};
4use log::info;
5use std::env;
6use std::path::PathBuf;
7use std::time::Duration;
8
9use crate::maintenance::MaintenanceManager;
10
11#[derive(Parser)]
12pub struct MaintenanceArgs {
13 #[arg(short = 'd', long)]
15 project_dir: Option<PathBuf>,
16
17 #[command(subcommand)]
18 action: MaintenanceAction,
19}
20
21#[derive(Subcommand)]
22enum MaintenanceAction {
23 Cleanup {
25 #[arg(short, long, default_value = "300")]
27 max_age: u64,
28 },
29 Clear,
31 Status,
33}
34
35pub fn execute(args: MaintenanceArgs) -> anyhow::Result<()> {
36 let project_dir = args
37 .project_dir
38 .unwrap_or_else(|| env::current_dir().expect("Failed to get current directory"));
39
40 info!(
41 "Running maintenance operations in: {}",
42 project_dir.display()
43 );
44
45 let manager = MaintenanceManager::new(&project_dir)?;
46
47 match args.action {
48 MaintenanceAction::Cleanup { max_age } => {
49 let duration = Duration::from_secs(max_age);
50 manager.cleanup_stale_updates(duration);
51 }
52 MaintenanceAction::Clear => {
53 manager.clear_all_updates();
54 }
55 MaintenanceAction::Status => {
56 manager.show_status();
57 }
58 }
59
60 Ok(())
61}