orbiton/commands/
maintenance.rs

1// Maintenance command for cleanup operations
2
3use 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    /// Project directory (defaults to current directory)
14    #[arg(short = 'd', long)]
15    project_dir: Option<PathBuf>,
16
17    #[command(subcommand)]
18    action: MaintenanceAction,
19}
20
21#[derive(Subcommand)]
22enum MaintenanceAction {
23    /// Clean up stale HMR updates
24    Cleanup {
25        /// Maximum age of updates to keep (in seconds)
26        #[arg(short, long, default_value = "300")]
27        max_age: u64,
28    },
29    /// Clear all pending HMR updates
30    Clear,
31    /// Show maintenance status
32    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}