CLI fail gracefully on unknown command

This commit is contained in:
Anand Thakker 2015-12-09 07:04:23 -05:00
parent d265cb3cec
commit ea25fadea6
2 changed files with 15 additions and 0 deletions

View File

@ -67,6 +67,13 @@ function parseArgs() {
var command = argv._[0],
inputs = argv._.slice(1);
if (!commands[command]) {
yargs.showHelp();
var suggestion = [argv['$0'], 'build'].concat(process.argv.slice(2)).join(' ');
process.stderr.write('Unknown command: ' + command + '. Did you mean "' + suggestion + '"?\n');
process.exit(1);
}
if (inputs.length == 0) {
try {
var p = require(path.resolve('package.json'));

View File

@ -122,6 +122,14 @@ test('invalid arguments', function (group) {
});
}, options);
group.test('bad command', function (t) {
documentation(['-f html fixture/internal.input.js'], function (err, stdout, stderr) {
t.ok(err.code, 'exits nonzero');
t.ok(stderr.match(/Unknown command/), 'reports unknown command');
t.end();
});
});
group.end();
});