Skip to content

Commit 68d4ad0

Browse files
committed
added unmatched and invalid args response
1 parent a273f0e commit 68d4ad0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

bin/cmd.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,21 @@ program
5858
});
5959
});
6060

61+
// error on unknown commands
62+
// ref: https://github.com/tj/commander.js#custom-event-listeners
63+
program
64+
.on('command:*', function () {
65+
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
66+
process.exit(1);
67+
});
68+
6169
program.parse(process.argv);
70+
71+
// check if no command line args are provided
72+
// ref: https://github.com/tj/commander.js/issues/7#issuecomment-32448653
73+
var NO_COMMAND_SPECIFIED = program.args.length === 0;
74+
75+
if (NO_COMMAND_SPECIFIED) {
76+
// user did not supply args, so show --help
77+
program.help();
78+
}

0 commit comments

Comments
 (0)