Skip to content

Commit

Permalink
Update commander
Browse files Browse the repository at this point in the history
  • Loading branch information
asamuzaK committed Feb 4, 2024
1 parent 504e274 commit 8d839bf
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
21 changes: 12 additions & 9 deletions modules/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name>', 'specify directory')
.option('-i, --info', 'console info')
.action(cleanDirectory);
commander.command('update').alias('u').description('update schemas')
.option('-c, --channel <name>', '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 <name>', '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 <name>', 'specify the release channel')
.option('-i, --info', 'console info')
.action(updateSchemas);
}
commander.parse(args);
}
};
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions test/commander.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 8d839bf

Please sign in to comment.