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

fix the undefined in help #414 #416

Merged
merged 3 commits into from
Oct 11, 2015
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Command.prototype.command = function(name, desc, opts) {

Command.prototype.arguments = function (desc) {
return this.parseExpectedArgs(desc.split(/ +/));
}
};

/**
* Add an implicit `help [cmd]` subcommand
Expand Down Expand Up @@ -549,6 +549,7 @@ Command.prototype.executeSubCommand = function(argv, args, unknown) {
process.exit(1);
});

// Store the reference to the child process
this.runningCommand = proc;
};

Expand Down Expand Up @@ -836,7 +837,7 @@ Command.prototype.version = function(str, flags) {
*/

Command.prototype.description = function(str) {
if (0 == arguments.length) return this._description;
if (0 === arguments.length) return this._description;
this._description = str;
return this;
};
Expand Down Expand Up @@ -915,10 +916,10 @@ Command.prototype.optionHelp = function() {

// Prepend the help information
return [pad('-h, --help', width) + ' ' + 'output usage information']
.concat(this.options.map(function(option) {
return pad(option.flags, width) + ' ' + option.description;
.concat(this.options.map(function(option) {
return pad(option.flags, width) + ' ' + option.description;
}))
.join('\n');
.join('\n');
};

/**
Expand All @@ -940,14 +941,10 @@ Command.prototype.commandHelp = function() {

return [
cmd._name
+ (cmd._alias
? '|' + cmd._alias
: '')
+ (cmd.options.length
? ' [options]'
: '')
+ (cmd._alias ? '|' + cmd._alias : '')
+ (cmd.options.length ? ' [options]' : '')
+ ' ' + args
, cmd.description()
, cmd.description()
];
});

Expand All @@ -956,11 +953,12 @@ Command.prototype.commandHelp = function() {
}, 0);

return [
''
''
, ' Commands:'
, ''
, commands.map(function(cmd) {
return pad(cmd[0], width) + ' ' + cmd[1];
var desc = cmd[1] ? ' ' + cmd[1] : '';
return pad(cmd[0], width) + desc;
}).join('\n').replace(/^/gm, ' ')
, ''
].join('\n');
Expand Down
14 changes: 14 additions & 0 deletions test/test.command.help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var program = require('../')
, sinon = require('sinon').sandbox.create()
, should = require('should');


program.command('mycommand [options]');

program.parse(['node', 'test']);

program.commandHelp().should.equal('\n Commands:\n\n mycommand [options]\n');