Skip to content

Commit

Permalink
Merge pull request #980 from shadowspawn/feature/739-command-prefix
Browse files Browse the repository at this point in the history
Add parent command as prefix of subcommand
  • Loading branch information
shadowspawn committed Jun 24, 2019
2 parents ff156f0 + 5eefd9e commit f08adb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Expand Up @@ -1116,8 +1116,12 @@ Command.prototype.helpInformation = function() {
if (this._alias) {
cmdName = cmdName + '|' + this._alias;
}
var parentCmdNames = '';
for (var parentCmd = this.parent; parentCmd; parentCmd = parentCmd.parent) {
parentCmdNames = parentCmd.name() + ' ' + parentCmdNames;
}
var usage = [
'Usage: ' + cmdName + ' ' + this.usage(),
'Usage: ' + parentCmdNames + cmdName + ' ' + this.usage(),
''
];

Expand Down
8 changes: 8 additions & 0 deletions test/test.command.usage.js
@@ -0,0 +1,8 @@
var program = require('../')
, should = require('should');

program
.name('test')
.command('info [options]')

program.commands[0].helpInformation().should.startWith('Usage: test info [options]')

0 comments on commit f08adb2

Please sign in to comment.