Skip to content

Commit

Permalink
🐛 Fixes issue with help output
Browse files Browse the repository at this point in the history
Fixes issue with help output
  • Loading branch information
Pranav Prakash committed Oct 14, 2017
1 parent adc4083 commit 23cd662
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 9 deletions.
35 changes: 35 additions & 0 deletions bin/koa-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ process.exit = exit;

// CLI

/**
* Install an around function; AOP.
*/

function around(obj, method, fn) {
var old = obj[method];

obj[method] = function() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) args[i] = arguments[i];
return fn.call(this, old, args);
};
}

/**
* Install a before function; AOP.
*/
Expand Down Expand Up @@ -49,6 +63,27 @@ function confirm(msg, callback) {
});
}

around(program, 'optionMissingArgument', function(fn, args) {
program.outputHelp();
fn.apply(this, args);
return { args: [], unknown: [] };
});

before(program, 'outputHelp', function() {
// track if help was shown for unknown option
this._helpShown = true;
});

before(program, 'unknownOption', function() {
// allow unknown options if help was shown, to prevent trailing error
this._allowUnknownOption = this._helpShown;

// show help if not yet shown
if (!this._helpShown) {
program.outputHelp();
}
});

program
.name('koa-api')
.version(version, ' --version')
Expand Down
11 changes: 2 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "koa-api-generator",
"version": "1.0.3",
"version": "1.0.4",
"description": "Koa API generator",
"main": "./bin/koa-api.js",
"preferGlobal": true,
Expand All @@ -14,14 +14,7 @@
"type": "git",
"url": "git+ssh://git@github.com/pranavpr/koa-api-generator.git"
},
"keywords": [
"koa",
"koa2",
"api",
"generator",
"boilerplate",
"jest"
],
"keywords": ["koa", "koa2", "api", "generator", "boilerplate", "jest"],
"author": "Pranav Prakash <pranav@pranavprakash.net>",
"license": "MIT",
"bugs": {
Expand Down

0 comments on commit 23cd662

Please # to comment.