diff --git a/modules/commander.js b/modules/commander.js index 951d75b..860dbf1 100644 --- a/modules/commander.js +++ b/modules/commander.js @@ -37,15 +37,18 @@ export const parseCommand = args => { if (Array.isArray(args) && args.some(arg => reg.test(arg))) { commander.exitOverride(); commander.version(process.env.npm_package_version, '-v, --version'); - commander.command('clean').alias('c') - .description('clean directory') - .option('-d, --dir ', 'specify directory') - .option('-i, --info', 'console info') - .action(cleanDirectory); - commander.command('update').alias('u').description('update schemas') - .option('-c, --channel ', 'specify the release channel') - .option('-i, --info', 'console info') - .action(updateSchemas); + if (args.includes('clean') || args.includes('c')) { + commander.command('clean').alias('c') + .description('clean directory') + .option('-d, --dir ', 'specify directory') + .option('-i, --info', 'console info') + .action(cleanDirectory); + } else if (args.includes('update') || args.includes('u')) { + commander.command('update').alias('u').description('update schemas') + .option('-c, --channel ', 'specify the release channel') + .option('-i, --info', 'console info') + .action(updateSchemas); + } commander.parse(args); } }; diff --git a/package.json b/package.json index 10caf99..6c9fe60 100644 --- a/package.json +++ b/package.json @@ -14,14 +14,14 @@ "types": "types/index.d.ts", "dependencies": { "camelize": "^1.0.1", - "commander": "^11.1.0", + "commander": "^12.0.0", "decamelize": "^6.0.0", "json5": "^2.2.3", "sinon": "^17.0.1" }, "devDependencies": { "@types/firefox-webext-browser": "^120.0.0", - "@types/node": "^20.11.9", + "@types/node": "^20.11.16", "@types/sinon": "^17.0.3", "c8": "^9.1.0", "chai": "^5.0.3", @@ -34,7 +34,7 @@ "mocha": "^10.2.0", "npm-run-all": "^4.1.5", "typescript": "^5.3.3", - "undici": "^6.5.0" + "undici": "^6.6.0" }, "scripts": { "build": "npm run tsc && npm run lint && npm run test", diff --git a/test/commander.test.js b/test/commander.test.js index f30b5c8..905d90f 100644 --- a/test/commander.test.js +++ b/test/commander.test.js @@ -91,4 +91,44 @@ describe('parse command', () => { stubParse.restore(); stubVer.restore(); }); + + it('should parse', () => { + const stubParse = sinon.stub(commander, 'parse'); + const stubVer = sinon.stub(commander, 'version'); + const spyCmd = sinon.spy(commander, 'command'); + const i = stubParse.callCount; + const j = stubVer.callCount; + const k = spyCmd.callCount; + parseCommand([ + 'foo', + 'bar', + 'clean' + ]); + assert.strictEqual(stubParse.callCount, i + 1, 'called'); + assert.strictEqual(stubVer.callCount, j + 1, 'called'); + assert.strictEqual(spyCmd.callCount, k + 1, 'called'); + stubParse.restore(); + stubVer.restore(); + spyCmd.restore(); + }); + + it('should parse', () => { + const stubParse = sinon.stub(commander, 'parse'); + const stubVer = sinon.stub(commander, 'version'); + const spyCmd = sinon.spy(commander, 'command'); + const i = stubParse.callCount; + const j = stubVer.callCount; + const k = spyCmd.callCount; + parseCommand([ + 'foo', + 'bar', + 'update' + ]); + assert.strictEqual(stubParse.callCount, i + 1, 'called'); + assert.strictEqual(stubVer.callCount, j + 1, 'called'); + assert.strictEqual(spyCmd.callCount, k + 1, 'called'); + stubParse.restore(); + stubVer.restore(); + spyCmd.restore(); + }); });