From 61849d1d29a5d53c365136831f65afd38fc3fdd2 Mon Sep 17 00:00:00 2001 From: Jared Petersen Date: Sun, 16 Sep 2018 20:18:51 -0700 Subject: [PATCH 1/3] removed indentation from errors --- index.js | 10 +++++----- test/test.options.args.required.js | 2 +- test/test.variadic.args.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 53ec69854..e44d08ff0 100644 --- a/index.js +++ b/index.js @@ -793,7 +793,7 @@ Command.prototype.opts = function() { Command.prototype.missingArgument = function(name) { console.error(); - console.error(" error: missing required argument `%s'", name); + console.error("error: missing required argument `%s'", name); console.error(); process.exit(1); }; @@ -809,9 +809,9 @@ 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); @@ -827,7 +827,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("error: unknown option `%s'", flag); console.error(); process.exit(1); }; @@ -841,7 +841,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("error: variadic arguments must be last `%s'", name); console.error(); process.exit(1); }; diff --git a/test/test.options.args.required.js b/test/test.options.args.required.js index f809f3f67..ba20e44b2 100644 --- a/test/test.options.args.required.js +++ b/test/test.options.args.required.js @@ -15,7 +15,7 @@ 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 ' argument missing"); + info[1].should.equal("error: option `-c, --cheese ' argument missing"); process.exit(0) }); diff --git a/test/test.variadic.args.js b/test/test.variadic.args.js index 72cff8ae1..11bf13bba 100644 --- a/test/test.variadic.args.js +++ b/test/test.variadic.args.js @@ -59,6 +59,6 @@ console.error = oldConsoleError; [ '', - ' error: variadic arguments must be last `variadicArg\'', + 'error: variadic arguments must be last `variadicArg\'', '' ].join('\n').should.eql(errorMessage); From ae2cb035df99a8eefb0042a00a01274a1553350f Mon Sep 17 00:00:00 2001 From: Jared Petersen Date: Sun, 16 Sep 2018 20:30:09 -0700 Subject: [PATCH 2/3] removed newline above and below errors --- index.js | 8 -------- test/test.command.allowUnknownOption.js | 4 ++-- test/test.options.args.required.js | 4 ++-- test/test.variadic.args.js | 6 +----- 4 files changed, 5 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index e44d08ff0..5149bc071 100644 --- a/index.js +++ b/index.js @@ -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(); process.exit(1); }; @@ -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); } else { console.error("error: option `%s' argument missing", option.flags); } - console.error(); process.exit(1); }; @@ -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(); process.exit(1); }; @@ -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(); process.exit(1); }; diff --git a/test/test.command.allowUnknownOption.js b/test/test.command.allowUnknownOption.js index 7261dd95a..598d21d4d 100644 --- a/test/test.command.allowUnknownOption.js +++ b/test/test.command.allowUnknownOption.js @@ -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 @@ -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` diff --git a/test/test.options.args.required.js b/test/test.options.args.required.js index ba20e44b2..10eebc10b 100644 --- a/test/test.options.args.required.js +++ b/test/test.options.args.required.js @@ -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 ' argument missing"); + info.length.should.equal(1); + info[0].should.equal("error: option `-c, --cheese ' argument missing"); process.exit(0) }); diff --git a/test/test.variadic.args.js b/test/test.variadic.args.js index 11bf13bba..80bdad530 100644 --- a/test/test.variadic.args.js +++ b/test/test.variadic.args.js @@ -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); From 146680c3036a298b363addd0fb28fa0069463928 Mon Sep 17 00:00:00 2001 From: Jared Petersen Date: Sat, 29 Sep 2018 13:20:47 -0700 Subject: [PATCH 3/3] prefixed error messages with "error:" --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 5149bc071..9b4d92bd5 100644 --- a/index.js +++ b/index.js @@ -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); });