saveConfig static method
Save configuration to file
Implementation
static Future<void> saveConfig(CliConfig config) async {
try {
// Ensure directory exists
final dir = Directory(configDir);
if (!dir.existsSync()) {
dir.createSync(recursive: true);
}
// Write config file
final file = File(configPath);
final json = jsonEncode(config.toJson());
await file.writeAsString(json);
// Set restrictive permissions (600) - owner read/write only
if (Platform.isLinux || Platform.isMacOS) {
try {
Process.runSync('chmod', ['600', configPath]);
} catch (e) {
// If chmod fails, continue - file permissions may not be critical
}
}
} catch (e) {
throw Exception('Failed to save config: $e');
}
}