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 1e6fbab commit f821383
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"benchmark": "^2.1.4",
"c8": "^9.1.0",
"chai": "^5.0.3",
"commander": "^11.1.0",
"commander": "^12.0.0",
"esbuild": "^0.20.0",
"eslint": "^8.56.0",
"eslint-config-standard": "^17.1.0",
Expand Down
21 changes: 12 additions & 9 deletions scripts/commander.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,18 @@ export const cleanDirectory = (cmdOpts = {}) => {
export const parseCommand = args => {
const reg = /^(?:(?:--)?help|-h|clean|denoconf)$/;
if (Array.isArray(args) && args.some(arg => reg.test(arg))) {
commander.command('clean')
.description('clean directory')
.option('-d, --dir <name>', 'specify directory')
.option('-i, --info', 'console info')
.action(cleanDirectory);
commander.command('denoconf')
.description('create deno config file')
.option('-i, --info', 'console info')
.action(createDenoConfigFile);
if (args.includes('clean')) {
commander.command('clean')
.description('clean directory')
.option('-d, --dir <name>', 'specify directory')
.option('-i, --info', 'console info')
.action(cleanDirectory);
} else if (args.includes('denoconf')) {
commander.command('denoconf')
.description('create deno config file')
.option('-i, --info', 'console info')
.action(createDenoConfigFile);
}
commander.parse(args);
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/commander.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ describe('parse command', () => {
const j = spyCmd.callCount;
parseCommand(['foo', 'bar', 'clean']);
assert.strictEqual(stubParse.callCount, i + 1, 'called parse');
assert.strictEqual(spyCmd.callCount, j + 2, 'called command');
assert.strictEqual(spyCmd.callCount, j + 1, 'called command');
stubParse.restore();
spyCmd.restore();
stubAct.restore();
Expand All @@ -221,7 +221,7 @@ describe('parse command', () => {
const j = spyCmd.callCount;
parseCommand(['foo', 'bar', 'denoconf']);
assert.strictEqual(stubParse.callCount, i + 1, 'called parse');
assert.strictEqual(spyCmd.callCount, j + 2, 'called command');
assert.strictEqual(spyCmd.callCount, j + 1, 'called command');
stubParse.restore();
spyCmd.restore();
stubAct.restore();
Expand Down

0 comments on commit f821383

Please sign in to comment.