core: fix command parser

This commit is contained in:
undefined committed 2022-05-24 17:50:01 +08:00
1 parent 7785c7ee19
commit e31396468f
2 files changed
+19 -26

No files matched your search

+18 -25
View File
@@ -87,30 +87,12 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
fs.removeSync(dir); fs.removeSync(dir);
console.log('Successfully restored.'); console.log('Successfully restored.');
}); });
cli.command('addon add <name>').action((name) => { cli.command('addon [operation] [name]').action((operation, name) => {
for (let i = 0; i < addons.length; i++) { if (operation && !['add', 'remove', 'create'].includes(operation)) {
if (addons[i] === name) { console.log('Unknown operation.');
addons.splice(i, 1); return;
break;
} }
} if (operation === 'create') {
addons.push(name);
addons = Array.from(new Set(addons));
console.log('Current Addons: ', addons);
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
});
cli.command('addon remove <name>').action((name) => {
for (let i = 0; i < addons.length; i++) {
if (addons[i] === name) {
addons.splice(i, 1);
break;
}
}
addons = Array.from(new Set(addons));
console.log('Current Addons: ', addons);
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
});
cli.command('addon create [name]').action((name) => {
name ||= '/root/addon'; name ||= '/root/addon';
fs.mkdirSync(name); fs.mkdirSync(name);
child.execSync('yarn init -y', { cwd: name }); child.execSync('yarn init -y', { cwd: name });
@@ -119,9 +101,20 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
fs.mkdirSync(`${name}/public`); fs.mkdirSync(`${name}/public`);
addons.push(name); addons.push(name);
console.log(`Addon created at ${name}`); console.log(`Addon created at ${name}`);
}); return;
cli.command('addon').action(() => { }
if (operation && name) {
for (let i = 0; i < addons.length; i++) {
if (addons[i] === name) {
addons.splice(i, 1);
break;
}
}
}
if (operation === 'add' && name) addons.push(name);
addons = Array.from(new Set(addons));
console.log('Current Addons: ', addons); console.log('Current Addons: ', addons);
fs.writeFileSync(addonPath, JSON.stringify(addons, null, 2));
}); });
cli.help(); cli.help();
cli.parse(); cli.parse();
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "3.13.10", "version": "3.13.11",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "src/loader", "main": "src/loader",
"module": "src/loader", "module": "src/loader",