Skip to main content

subx_cli/cli/
cache_args.rs

1//! Cache management command-line arguments and operations.
2//!
3//! This module defines the command-line interface for cache-related operations
4//! in SubX. The cache system stores intermediate results from AI analysis and
5//! other computationally expensive operations to improve performance and reduce
6//! API costs during development and testing.
7//!
8//! # Cache System Overview
9//!
10//! SubX maintains several types of caches:
11//! - **AI Analysis Cache**: Results from AI-powered file matching
12//! - **Audio Analysis Cache**: Speech pattern detection results
13//! - **Configuration Cache**: Processed configuration data
14//! - **Dry-run Cache**: Preview results that can be applied later
15//!
16//! # Cache Benefits
17//!
18//! - **Performance**: Avoid re-analyzing the same content
19//! - **Cost Savings**: Reduce AI API calls during testing
20//! - **Development**: Faster iteration during debugging
21//! - **Reliability**: Consistent results across multiple runs
22//!
23//! # Examples
24//!
25//! ```bash
26//! # Clear all cache data
27//! subx cache clear
28//!
29//! # View cache status (future enhancement)
30//! subx cache status
31//!
32//! # Selective cache clearing (future enhancement)
33//! subx cache clear --type ai
34//! ```
35
36use clap::{Args, Subcommand, ValueEnum};
37
38/// Command-line arguments for cache management operations.
39#[derive(Args, Debug)]
40pub struct CacheArgs {
41    /// The cache management action to perform
42    #[command(subcommand)]
43    pub action: CacheAction,
44}
45
46/// Cache management operations and subcommands.
47#[derive(Subcommand, Debug)]
48pub enum CacheAction {
49    /// Display cache status including size, age, and validity
50    Status(StatusArgs),
51    /// Apply cached dry-run results without calling the AI provider
52    Apply(ApplyArgs),
53    /// Undo the most recent batch of file operations
54    Rollback(RollbackArgs),
55    /// Clear cached data
56    Clear(ClearArgs),
57}
58
59/// Arguments for the `cache status` subcommand.
60#[derive(Args, Debug)]
61pub struct StatusArgs {
62    /// Output status in JSON format for scripting
63    #[arg(long)]
64    pub json: bool,
65}
66
67/// Arguments for the `cache apply` subcommand.
68#[derive(Args, Debug)]
69pub struct ApplyArgs {
70    /// Skip interactive confirmation prompt
71    #[arg(long)]
72    pub yes: bool,
73    /// Bypass staleness and validation checks
74    #[arg(long)]
75    pub force: bool,
76    /// Minimum confidence threshold (0-100) to filter operations
77    #[arg(long, value_parser = clap::value_parser!(u8).range(0..=100))]
78    pub confidence: Option<u8>,
79}
80
81/// Arguments for the `cache rollback` subcommand.
82#[derive(Args, Debug)]
83pub struct RollbackArgs {
84    /// Bypass integrity verification checks
85    #[arg(long)]
86    pub force: bool,
87}
88
89/// Arguments for the `cache clear` subcommand.
90#[derive(Args, Debug)]
91pub struct ClearArgs {
92    /// Type of data to clear
93    #[arg(long, value_enum, default_value_t = ClearType::All)]
94    pub r#type: ClearType,
95}
96
97/// Types of cache data that can be cleared.
98#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
99pub enum ClearType {
100    /// Clear only the match cache file
101    Cache,
102    /// Clear only the operation journal
103    Journal,
104    /// Clear both cache and journal
105    All,
106}