From 2365feb28bb4874744c859edaf42115187d21886 Mon Sep 17 00:00:00 2001 From: Dan Allen Date: Thu, 4 Jan 2018 23:40:14 -0700 Subject: [PATCH 1/3] resolves #739 add parent command as prefix of subcommand --- index.js | 5 ++++- test/test.command.usage.js | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/test.command.usage.js diff --git a/index.js b/index.js index cb82f55b9..115ce9476 100644 --- a/index.js +++ b/index.js @@ -1031,9 +1031,12 @@ Command.prototype.helpInformation = function() { if (this._alias) { cmdName = cmdName + '|' + this._alias; } + var ancestor = this + var prefix = [] + while ((ancestor = ancestor.parent)) prefix.push(ancestor.name() + ' ') var usage = [ '' - ,' Usage: ' + cmdName + ' ' + this.usage() + ,' Usage: ' + prefix.join('') + cmdName + ' ' + this.usage() , '' ]; diff --git a/test/test.command.usage.js b/test/test.command.usage.js new file mode 100644 index 000000000..fcfd39ec8 --- /dev/null +++ b/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('\n Usage: test info [options]') From cd6e6085c426fcc8815bac8247bc86a4757caa0b Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 23 Jun 2019 19:43:58 +1200 Subject: [PATCH 2/3] Fix order of nested parent commands in help - fix multiple parent order (although multiple levels not yet supported) - without using any new javascript features --- index.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 2be52ff9d..5380a4a58 100644 --- a/index.js +++ b/index.js @@ -1116,11 +1116,12 @@ Command.prototype.helpInformation = function() { if (this._alias) { cmdName = cmdName + '|' + this._alias; } - var ancestor = this; - var prefix = []; - while ((ancestor = ancestor.parent)) prefix.push(ancestor.name() + ' '); + var parentCmdNames = ''; + for (var parentCmd = this.parent; parentCmd; parentCmd = parentCmd.parent) { + parentCmdNames = parentCmd.name() + ' ' + parentCmdNames; + } var usage = [ - 'Usage: ' + prefix.join('') + cmdName + ' ' + this.usage(), + 'Usage: ' + parentCmdNames + cmdName + ' ' + this.usage(), '' ]; From 5eefd9e732cc223ce2236848fc71270e836a5aef Mon Sep 17 00:00:00 2001 From: John Gee Date: Sun, 23 Jun 2019 19:51:08 +1200 Subject: [PATCH 3/3] Fix new test for latest help style --- test/test.command.usage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test.command.usage.js b/test/test.command.usage.js index fcfd39ec8..f7c9d69db 100644 --- a/test/test.command.usage.js +++ b/test/test.command.usage.js @@ -5,4 +5,4 @@ program .name('test') .command('info [options]') -program.commands[0].helpInformation().should.startWith('\n Usage: test info [options]') +program.commands[0].helpInformation().should.startWith('Usage: test info [options]')