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};
37
38/// Command-line arguments for cache management operations.
39///
40/// The cache command provides utilities for managing SubX's internal cache
41/// system, which stores results from computationally expensive operations
42/// such as AI analysis, audio processing, and file matching results.
43///
44/// # Cache Types Managed
45///
46/// - **AI Analysis Results**: Cached responses from AI matching operations
47/// - **Dry-run Results**: Preview results that haven't been applied yet
48/// - **Audio Analysis Data**: Speech pattern detection and timing analysis
49/// - **Processed Configuration**: Validated and normalized configuration data
50///
51/// # Use Cases
52///
53/// - **Development**: Clear cache between test runs
54/// - **Troubleshooting**: Reset cache when encountering issues
55/// - **Maintenance**: Periodic cleanup of stale cache data
56/// - **Testing**: Ensure clean state for automated tests
57///
58/// # Examples
59///
60/// ```rust
61/// use subx_cli::cli::{CacheArgs, CacheAction};
62///
63/// let clear_args = CacheArgs {
64///     action: CacheAction::Clear,
65/// };
66/// ```
67#[derive(Args, Debug)]
68pub struct CacheArgs {
69    /// The cache management action to perform.
70    ///
71    /// Specifies which cache operation should be executed. Currently supports
72    /// clearing operations, with plans for additional cache management features
73    /// such as status viewing, selective clearing, and cache statistics.
74    #[command(subcommand)]
75    pub action: CacheAction,
76}
77
78/// Cache management operations and subcommands.
79///
80/// Defines the available cache management operations that can be performed
81/// through the SubX CLI. Each operation targets specific aspects of the
82/// cache system to provide granular control over cached data.
83///
84/// # Current Operations
85///
86/// - **Clear**: Remove all or specific types of cached data
87///
88/// # Future Enhancements
89///
90/// Planned cache operations include:
91/// - **Status**: View cache size, age, and utilization statistics
92/// - **Validate**: Check cache integrity and consistency
93/// - **Optimize**: Compact and defragment cache storage
94/// - **Export/Import**: Backup and restore cache data
95///
96/// # Examples
97///
98/// ```rust
99/// use subx_cli::cli::CacheAction;
100///
101/// // Clear all cache data
102/// let clear_action = CacheAction::Clear;
103/// ```
104#[derive(Subcommand, Debug)]
105pub enum CacheAction {
106    /// Clear all cached data including dry-run results and AI analysis.
107    ///
108    /// This operation removes all cached data from the SubX cache system,
109    /// including:
110    ///
111    /// # Data Cleared
112    ///
113    /// - **Dry-run Results**: Cached matching results from preview operations
114    /// - **AI Analysis Cache**: Stored results from AI-powered file matching
115    /// - **Audio Analysis Cache**: Speech pattern detection results
116    /// - **Temporary Files**: Processing artifacts and intermediate data
117    ///
118    /// # Impact
119    ///
120    /// After clearing the cache:
121    /// - Next AI operations will require fresh API calls (increased cost/time)
122    /// - Audio analysis will need to be re-performed
123    /// - Dry-run results will need to be regenerated
124    /// - Configuration cache will be rebuilt on next access
125    ///
126    /// # Safety
127    ///
128    /// This operation is safe and non-destructive:
129    /// - No actual subtitle or video files are affected
130    /// - Only internal cache data is removed
131    /// - All data can be regenerated through normal operations
132    ///
133    /// # Examples
134    ///
135    /// ```bash
136    /// # Clear all cache data
137    /// subx cache clear
138    /// ```
139    ///
140    /// # Use Cases
141    ///
142    /// - **Development**: Reset state between test iterations
143    /// - **Troubleshooting**: Clear potentially corrupted cache data
144    /// - **Maintenance**: Periodic cleanup to reclaim disk space
145    /// - **Fresh Start**: Ensure clean state for important operations
146    Clear,
147}