subx_cli/cli/
config_args.rs

1//! Configuration management command-line arguments and operations.
2//!
3//! This module defines the command-line interface for configuration management
4//! in SubX. It provides comprehensive tools for viewing, modifying, and maintaining
5//! configuration settings that control various aspects of subtitle processing,
6//! AI integration, and application behavior.
7//!
8//! # Configuration System
9//!
10//! SubX uses a hierarchical configuration system with multiple sources:
11//! - **System-wide**: Global defaults for all users
12//! - **User-specific**: Personal settings in user config directory
13//! - **Project-specific**: Local settings for specific projects
14//! - **Environment variables**: Runtime configuration overrides
15//! - **Command-line**: Highest priority, temporary overrides
16//!
17//! # Configuration Categories
18//!
19//! - **General**: Basic application behavior and preferences
20//! - **AI Settings**: API endpoints, models, and parameters
21//! - **Audio Processing**: Audio analysis and synchronization settings
22//! - **Format Options**: Default output formats and encoding preferences
23//! - **Performance**: Parallel processing and caching configuration
24//!
25//! # Examples
26//!
27//! ```bash
28//! # View all configuration settings
29//! subx config list
30//!
31//! # Get specific setting
32//! subx config get ai.provider
33//!
34//! # Set AI provider
35//! subx config set ai.provider openai
36//! subx config set ai.provider openrouter
37//!
38//! # Reset to defaults
39//! subx config reset
40//! ```
41
42//! # Advanced Usage Examples
43//!
44//! ## Setting Complex Values
45//! ```bash
46//! # Set AI provider with API key
47//! subx-cli config set ai.provider openai
48//! subx-cli config set ai.provider openrouter
49//! subx-cli config set ai.api_key "sk-1234567890abcdef"
50//! subx-cli config set ai.api_key "test-openrouter-key"
51//! subx-cli config set ai.base_url "https://api.openai.com/v1"
52//! subx-cli config set ai.model "deepseek/deepseek-r1-0528:free"
53//!
54//! # Configure audio processing and VAD settings
55//! subx-cli config set sync.max_offset_seconds 15.0
56//! subx-cli config set sync.default_method vad
57//! subx-cli config set sync.vad.enabled true
58//! subx-cli config set sync.vad.sensitivity 0.8
59//!
60//! # Set performance options
61//! subx-cli config set parallel.max_workers 4
62//! subx-cli config set general.max_concurrent_jobs 8
63//! ```
64//!
65//! ## Boolean Value Formats
66//! ```bash
67//! # All of these set the value to true
68//! subx-cli config set general.backup_enabled true
69//! subx-cli config set general.backup_enabled 1
70//! subx-cli config set general.backup_enabled yes
71//! subx-cli config set general.backup_enabled on
72//! subx-cli config set general.backup_enabled enabled
73//!
74//! # All of these set the value to false
75//! subx-cli config set general.backup_enabled false
76//! subx-cli config set general.backup_enabled 0
77//! subx-cli config set general.backup_enabled no
78//! subx-cli config set general.backup_enabled off
79//! subx-cli config set general.backup_enabled disabled
80//! ```
81//!
82//! ## Clearing Optional Values
83//! ```bash
84//! # Clear API key (set to None)
85//! subx-cli config set ai.api_key ""
86//! ```
87
88// src/cli/config_args.rs
89use clap::{Args, Subcommand};
90
91/// Command-line arguments for configuration management operations.
92#[derive(Args, Debug)]
93pub struct ConfigArgs {
94    /// The configuration management action to perform
95    #[command(subcommand)]
96    pub action: ConfigAction,
97}
98
99/// Configuration management operations and subcommands.
100///
101/// Defines the available configuration management operations that can be
102/// performed through the SubX CLI. Each operation provides specific
103/// functionality for different aspects of configuration management.
104///
105/// # Operation Categories
106///
107/// - **Viewing**: Get and list operations for inspecting settings
108/// - **Modification**: Set operation for changing configuration values
109/// - **Maintenance**: Reset operation for restoring defaults
110///
111/// # Validation and Safety
112///
113/// All configuration operations include:
114/// - **Type validation**: Ensure values match expected data types
115/// - **Range checking**: Validate numeric values are within acceptable ranges
116/// - **Format verification**: Check string values follow required patterns
117/// - **Dependency checking**: Verify related settings are compatible
118///
119/// # Examples
120///
121/// ```rust
122/// use subx_cli::cli::ConfigAction;
123///
124/// // Different configuration operations
125/// let set_provider = ConfigAction::Set {
126///     key: "ai.provider".to_string(),
127///     value: "openai".to_string(),
128/// };
129///
130/// let get_provider = ConfigAction::Get {
131///     key: "ai.provider".to_string(),
132/// };
133///
134/// let list_all = ConfigAction::List;
135/// let reset_config = ConfigAction::Reset;
136/// ```
137#[derive(Subcommand, Debug)]
138pub enum ConfigAction {
139    /// Set a configuration value with validation and type checking
140    Set {
141        /// Configuration key in dot notation (e.g., "ai.provider", "general.timeout")
142        key: String,
143        /// New value for the configuration setting
144        value: String,
145    },
146
147    /// Retrieve and display a specific configuration value
148    Get {
149        /// Configuration key to retrieve (e.g., "ai.provider", "general.timeout")
150        key: String,
151    },
152
153    /// List all configuration settings with their current values
154    List,
155
156    /// Reset configuration to default values with backup creation
157    Reset,
158}