Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

Natural Language Configuration Modifications: Figure out and make write access work for the repository's config. #890

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/utils/changeConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const fs = require('fs');
const yaml = require('js-yaml');

const CONFIG_FILE_PATH = 'config.yml';

function readConfig() {
try {
const fileContents = fs.readFileSync(CONFIG_FILE_PATH, 'utf8');
return yaml.safeLoad(fileContents);
} catch (error) {
console.error('Error reading configuration file:', error);
return {};
}
}

function writeConfig(config) {
try {
const yamlString = yaml.dump(config, { noRefs: true });
fs.writeFileSync(CONFIG_FILE_PATH, yamlString, 'utf8');
} catch (error) {
console.error('Error writing to configuration file:', error);
}
}

function modifyConfig(command, value) {
const config = readConfig();

if (command === 'disable' && config.hasOwnProperty('start_command')) {
config.start_command = null;
} else if (command === 'set' && config.hasOwnProperty('max_users')) {
config.max_users = value;
} else if (command === 'toggle' && config.hasOwnProperty('enable_feature_x')) {
config.enable_feature_x = !config.enable_feature_x;
}

writeConfig(config);
}

// Command line arguments
const [,, command, value] = process.argv;

if (!command) {
console.error('Usage: node script.js <command> [value]');
process.exit(1);
}

modifyConfig(command, value);
console.log('Configuration updated successfully.');