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

Add parent command as prefix of subcommand #980

Merged
merged 5 commits into from Jun 24, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nit, you can shorten this by having the loop above mutate cmdName instead of , since it's not used below.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I did wonder about that too, but went for long and clear.

''
];

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]')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a nested command test too, if that's explicitly being handled.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nested commands are not currently supported! But since the code included a loop, I thought it should do it right for the possible future. :-)