set method
Set a configuration value
Implementation
@cliCommand
Future<void> set(
/// Configuration key
String key,
/// Configuration value
String value,
) async {
info("Setting configuration: $key = $value");
final configFile = File(configPath);
if (!configFile.existsSync()) {
error("Configuration not found. Run 'claudio config init' first.");
return;
}
// Read existing config
final content = await configFile.readAsString();
final lines = content.split('\n');
// Find and update the key, or append it
bool found = false;
final updatedLines = <String>[];
for (final line in lines) {
if (line.trim().startsWith('$key:')) {
updatedLines.add('$key: $value');
found = true;
} else {
updatedLines.add(line);
}
}
if (!found) {
updatedLines.add('$key: $value');
}
await configFile.writeAsString(updatedLines.join('\n'));
success("Configuration updated: $key = $value");
}