pub async fn execute(
args: ConfigArgs,
config_service: &dyn ConfigService,
) -> SubXResult<()>
Expand description
Execute configuration management operations with validation and type safety.
This function provides the main entry point for all configuration management operations, including setting values, retrieving current configuration, listing all settings, and resetting to defaults. It includes comprehensive validation, error handling, and user-friendly output formatting.
§Operation Workflow
§Set Operation
- Configuration Loading: Load current configuration from all sources
- Key Validation: Verify configuration key exists and is writable
- Value Parsing: Convert string value to appropriate data type
- Constraint Checking: Validate value meets all requirements
- Dependency Verification: Check related settings compatibility
- Backup Creation: Save current value for potential rollback
- Value Application: Update configuration with new value
- Persistence: Save updated configuration to appropriate file
- Confirmation: Display success message with applied value
§Get Operation
- Configuration Loading: Load current effective configuration
- Key Resolution: Locate requested configuration setting
- Source Identification: Determine where value originates
- Value Formatting: Format value for appropriate display
- Metadata Retrieval: Gather type and constraint information
- Output Generation: Create comprehensive information display
§List Operation
- Configuration Loading: Load all configuration settings
- Categorization: Group settings by functional area
- Source Analysis: Identify customized vs. default values
- Formatting: Prepare values for tabular display
- Output Generation: Create organized configuration overview
§Reset Operation
- Current State Backup: Create timestamped configuration backup
- User Confirmation: Interactive confirmation for destructive operation
- Default Restoration: Replace all settings with built-in defaults
- Validation: Verify reset configuration is valid
- Persistence: Save default configuration to user config file
- Confirmation: Display reset completion and backup location
§Type System Integration
The configuration system provides strong typing with automatic conversion:
- Boolean Values: “true”, “false”, “1”, “0”, “yes”, “no”
- Integer Values: Decimal notation with range validation
- Float Values: Decimal notation with precision preservation
- String Values: UTF-8 text with format validation where applicable
- Array Values: JSON array format for complex configuration
§Validation Framework
Each configuration setting includes comprehensive validation:
- Type Constraints: Must match expected data type
- Range Limits: Numeric values within acceptable bounds
- Format Requirements: String values matching required patterns
- Dependency Rules: Related settings must be compatible
- Security Checks: Sensitive values properly protected
§Arguments
args
- Configuration command arguments containing the specific operation to perform (set, get, list, or reset) along with any required parameters such as key names and values.
§Returns
Returns Ok(())
on successful operation completion, or an error describing:
- Configuration loading or parsing failures
- Invalid configuration keys or malformed key paths
- Type conversion or validation errors
- File system access problems during persistence
- User cancellation of destructive operations
§Error Categories
§Configuration Errors
- Invalid Key: Specified configuration key does not exist
- Type Mismatch: Value cannot be converted to expected type
- Range Error: Numeric value outside acceptable range
- Format Error: String value doesn’t match required pattern
- Dependency Error: Value conflicts with related settings
§System Errors
- File Access: Cannot read or write configuration files
- Permission Error: Insufficient privileges for operation
- Disk Space: Insufficient space for configuration persistence
- Corruption: Configuration file is damaged or invalid
§Security Considerations
- Sensitive Values: API keys and credentials are properly masked in output
- File Permissions: Configuration files created with appropriate permissions
- Backup Protection: Backup files inherit security settings
- Validation: All input values sanitized and validated
§Examples
ⓘ
use subx_cli::cli::{ConfigArgs, ConfigAction};
use subx_cli::commands::config_command;
// Configure AI service with API key
let ai_setup = ConfigArgs {
action: ConfigAction::Set {
key: "ai.openai.api_key".to_string(),
value: "sk-1234567890abcdef".to_string(),
},
};
config_command::execute(ai_setup).await?;
// Adjust audio processing sensitivity
let audio_tuning = ConfigArgs {
action: ConfigAction::Set {
key: "audio.correlation_threshold".to_string(),
value: "0.85".to_string(),
},
};
config_command::execute(audio_tuning).await?;
// View complete configuration
let view_all = ConfigArgs {
action: ConfigAction::List,
};
config_command::execute(view_all).await?;
// Reset to clean state
let reset_config = ConfigArgs {
action: ConfigAction::Reset,
};
config_command::execute(reset_config).await?;