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//!
37//! # Reset to defaults
38//! subx config reset
39//! ```
40
41//! # Advanced Usage Examples
42//!
43//! ## Setting Complex Values
44//! ```bash
45//! # Set AI provider with API key
46//! subx-cli config set ai.provider openai
47//! subx-cli config set ai.api_key "sk-1234567890abcdef"
48//! subx-cli config set ai.base_url "https://api.openai.com/v1"
49//!
50//! # Configure audio processing and VAD settings
51//! subx-cli config set sync.max_offset_seconds 15.0
52//! subx-cli config set sync.default_method vad
53//! subx-cli config set sync.vad.enabled true
54//! subx-cli config set sync.vad.sensitivity 0.8
55//!
56//! # Set performance options
57//! subx-cli config set parallel.max_workers 4
58//! subx-cli config set general.max_concurrent_jobs 8
59//! ```
60//!
61//! ## Boolean Value Formats
62//! ```bash
63//! # All of these set the value to true
64//! subx-cli config set general.backup_enabled true
65//! subx-cli config set general.backup_enabled 1
66//! subx-cli config set general.backup_enabled yes
67//! subx-cli config set general.backup_enabled on
68//! subx-cli config set general.backup_enabled enabled
69//!
70//! # All of these set the value to false
71//! subx-cli config set general.backup_enabled false
72//! subx-cli config set general.backup_enabled 0
73//! subx-cli config set general.backup_enabled no
74//! subx-cli config set general.backup_enabled off
75//! subx-cli config set general.backup_enabled disabled
76//! ```
77//!
78//! ## Clearing Optional Values
79//! ```bash
80//! # Clear API key (set to None)
81//! subx-cli config set ai.api_key ""
82//! ```
83
84// src/cli/config_args.rs
85use clap::{Args, Subcommand};
86
87/// Command-line arguments for configuration management operations.
88#[derive(Args, Debug)]
89pub struct ConfigArgs {
90 /// The configuration management action to perform
91 #[command(subcommand)]
92 pub action: ConfigAction,
93}
94
95/// Configuration management operations and subcommands.
96///
97/// Defines the available configuration management operations that can be
98/// performed through the SubX CLI. Each operation provides specific
99/// functionality for different aspects of configuration management.
100///
101/// # Operation Categories
102///
103/// - **Viewing**: Get and list operations for inspecting settings
104/// - **Modification**: Set operation for changing configuration values
105/// - **Maintenance**: Reset operation for restoring defaults
106///
107/// # Validation and Safety
108///
109/// All configuration operations include:
110/// - **Type validation**: Ensure values match expected data types
111/// - **Range checking**: Validate numeric values are within acceptable ranges
112/// - **Format verification**: Check string values follow required patterns
113/// - **Dependency checking**: Verify related settings are compatible
114///
115/// # Examples
116///
117/// ```rust
118/// use subx_cli::cli::ConfigAction;
119///
120/// // Different configuration operations
121/// let set_provider = ConfigAction::Set {
122/// key: "ai.provider".to_string(),
123/// value: "openai".to_string(),
124/// };
125///
126/// let get_provider = ConfigAction::Get {
127/// key: "ai.provider".to_string(),
128/// };
129///
130/// let list_all = ConfigAction::List;
131/// let reset_config = ConfigAction::Reset;
132/// ```
133#[derive(Subcommand, Debug)]
134pub enum ConfigAction {
135 /// Set a configuration value with validation and type checking
136 Set {
137 /// Configuration key in dot notation (e.g., "ai.provider", "general.timeout")
138 key: String,
139 /// New value for the configuration setting
140 value: String,
141 },
142
143 /// Retrieve and display a specific configuration value
144 Get {
145 /// Configuration key to retrieve (e.g., "ai.provider", "general.timeout")
146 key: String,
147 },
148
149 /// List all configuration settings with their current values
150 List,
151
152 /// Reset configuration to default values with backup creation
153 Reset,
154}