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