Skip to content

Commit

Permalink
fix: show “invalid command” error
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jun 16, 2019
1 parent 12c2926 commit c7c7b58
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Sade {
usage = usage.join(' '); // to string

this.tree[cmd] = { usage, options:[], alias:{}, default:{}, examples:[] };
desc && this.describe(desc);
if (desc) this.describe(desc);

return this;
}
Expand Down Expand Up @@ -112,8 +112,8 @@ class Sade {
cmd = this.tree[name];
arr.unshift(name);
offset++;
} else if (name) {
return $.error(bin, `Invalid command: ${name}`);
} else if (tmp) {
return $.error(bin, `Invalid command: ${tmp}`);
} //=> else: cmd not specified, wait for now...
}

Expand Down
2 changes: 1 addition & 1 deletion test/usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test('(usage) basic :: error :: invalid command', t => {
t.is(pid.status, 1, 'exits with error code');
t.is(
pid.stderr.toString(),
'\n ERROR\n Invalid command: foobar.\n\n Run `$ bin --help` for more info.\n\n',
'\n ERROR\n Invalid command: foobar\n\n Run `$ bin --help` for more info.\n\n',
'~> stderr has "Invalid command: foobar" error message'
);
t.is(pid.stdout.length, 0, '~> stdout is empty');
Expand Down

0 comments on commit c7c7b58

Please sign in to comment.