Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix - Error output #862

Merged
merged 3 commits into from Oct 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 7 additions & 15 deletions index.js
Expand Up @@ -580,9 +580,9 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
proc.on('close', process.exit.bind(process));
proc.on('error', function(err) {
if (err.code === 'ENOENT') {
console.error('%s(1) does not exist, try --help', bin);
console.error('error: %s(1) does not exist, try --help', bin);
} else if (err.code === 'EACCES') {
console.error('%s(1) not executable. try chmod or run with root', bin);
console.error('error: %s(1) not executable. try chmod or run with root', bin);
}
process.exit(1);
});
Expand Down Expand Up @@ -792,9 +792,7 @@ Command.prototype.opts = function() {
*/

Command.prototype.missingArgument = function(name) {
console.error();
console.error(" error: missing required argument `%s'", name);
console.error();
console.error("error: missing required argument `%s'", name);
process.exit(1);
};

Expand All @@ -807,13 +805,11 @@ Command.prototype.missingArgument = function(name) {
*/

Command.prototype.optionMissingArgument = function(option, flag) {
console.error();
if (flag) {
console.error(" error: option `%s' argument missing, got `%s'", option.flags, flag);
console.error("error: option `%s' argument missing, got `%s'", option.flags, flag);
} else {
console.error(" error: option `%s' argument missing", option.flags);
console.error("error: option `%s' argument missing", option.flags);
}
console.error();
process.exit(1);
};

Expand All @@ -826,9 +822,7 @@ Command.prototype.optionMissingArgument = function(option, flag) {

Command.prototype.unknownOption = function(flag) {
if (this._allowUnknownOption) return;
console.error();
console.error(" error: unknown option `%s'", flag);
console.error();
console.error("error: unknown option `%s'", flag);
process.exit(1);
};

Expand All @@ -840,9 +834,7 @@ Command.prototype.unknownOption = function(flag) {
*/

Command.prototype.variadicArgNotLast = function(name) {
console.error();
console.error(" error: variadic arguments must be last `%s'", name);
console.error();
console.error("error: variadic arguments must be last `%s'", name);
process.exit(1);
};

Expand Down
4 changes: 2 additions & 2 deletions test/test.command.allowUnknownOption.js
Expand Up @@ -13,7 +13,7 @@ program
.option('-p, --pepper', 'add pepper');
program.parse('node test -m'.split(' '));

stubError.callCount.should.equal(3);
stubError.callCount.should.equal(1);


// test subcommand
Expand All @@ -24,7 +24,7 @@ program
});
program.parse('node test sub -m'.split(' '));

stubError.callCount.should.equal(3);
stubError.callCount.should.equal(1);
stubExit.calledOnce.should.be.true();

// command with `allowUnknownOption`
Expand Down
4 changes: 2 additions & 2 deletions test/test.options.args.required.js
Expand Up @@ -14,8 +14,8 @@ console.error = function () {

process.on('exit', function (code) {
code.should.equal(1);
info.length.should.equal(3);
info[1].should.equal(" error: option `-c, --cheese <type>' argument missing");
info.length.should.equal(1);
info[0].should.equal("error: option `-c, --cheese <type>' argument missing");
process.exit(0)
});

Expand Down
6 changes: 1 addition & 5 deletions test/test.variadic.args.js
Expand Up @@ -57,8 +57,4 @@ try {
process.exit = oldProcessExit;
console.error = oldConsoleError;

[
'',
' error: variadic arguments must be last `variadicArg\'',
''
].join('\n').should.eql(errorMessage);
'error: variadic arguments must be last `variadicArg\''.should.eql(errorMessage);