Skip to content

Commit

Permalink
fix(help): Display other commands when default command is present (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
Szpadel authored and mattallty committed Oct 20, 2017
1 parent cc253d9 commit 8df56e8
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions lib/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Help {
${this._getUsage(command)}`;

if (!command && this._program._commands.length > 1) {
if (!command || command.name() === '' && this._program._commands.length > 1) {
help += "\n\n " + this._getCommands();
}

Expand All @@ -52,11 +52,14 @@ class Help {

_getCommands() {
const commandTable = this._getSimpleTable();
this._program._commands.forEach(cmd => {
commandTable.push(
[chalk.magenta(cmd.getSynopsis()), cmd.description()]
);
});
this._program._commands
// don't include default command
.filter((c) => c.name() !== '')
.forEach(cmd => {
commandTable.push(
[chalk.magenta(cmd.getSynopsis()), cmd.description()]
);
});
commandTable.push([chalk.magenta('help <command>'), 'Display help for a specific command']);
return chalk.bold('COMMANDS') + "\n\n" + colorize(commandTable.toString());
}
Expand Down Expand Up @@ -112,14 +115,15 @@ class Help {
}



_getSimpleTable() {
return new Table({
chars: { 'top': '' , 'top-mid': '' , 'top-left': '' , 'top-right': ''
, 'bottom': '' , 'bottom-mid': '' , 'bottom-left': '' , 'bottom-right': ''
, 'left': '' , 'left-mid': '' , 'mid': '' , 'mid-mid': ''
, 'right': '' , 'right-mid': '' , 'middle': ' ' },
style: { 'padding-left': 5, 'padding-right': 0 }
chars: {
'top': '', 'top-mid': '', 'top-left': '', 'top-right': ''
, 'bottom': '', 'bottom-mid': '', 'bottom-left': '', 'bottom-right': ''
, 'left': '', 'left-mid': '', 'mid': '', 'mid-mid': ''
, 'right': '', 'right-mid': '', 'middle': ' '
},
style: {'padding-left': 5, 'padding-right': 0}
});
}

Expand Down

0 comments on commit 8df56e8

Please sign in to comment.