Skip to content

Commit

Permalink
fix: help strings for nested commands were missing parent commands (#990
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bcoe committed Oct 19, 2017
1 parent 3c8ac1d commit cd1ca15
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/usage.js
Expand Up @@ -197,13 +197,16 @@ module.exports = function usage (yargs, y18n) {
if (commands.length) {
ui.div(__('Commands:'))

const context = yargs.getContext()
const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : ''

commands.forEach((command) => {
const commandString = `${base$0} ${command[0].replace(/^\$0 ?/, '')}` // drop $0 from default commands.
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}` // drop $0 from default commands.
ui.span(
{
text: commandString,
padding: [0, 2, 0, 2],
width: maxWidth(commands, theWrap, base$0) + 4
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4
},
{text: command[1]}
)
Expand Down
6 changes: 3 additions & 3 deletions test/command.js
Expand Up @@ -536,8 +536,8 @@ describe('Command', () => {
'command dream [command] [opts]',
'Go to sleep and dream',
'Commands:',
' command of-memory <memory> Dream about a specific memory',
' command within-a-dream [command] [opts] Dream within a dream',
' command dream of-memory <memory> Dream about a specific memory',
' command dream within-a-dream [command] [opts] Dream within a dream',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('Command', () => {
'command cmd <sub>',
'Try a command',
'Commands:',
' command sub Run the subcommand',
' command cmd sub Run the subcommand',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
Expand Down
4 changes: 2 additions & 2 deletions test/yargs.js
Expand Up @@ -338,7 +338,7 @@ describe('yargs dsl tests', () => {
})
})

it("skips executing top-level command if builder's help is executed", () => {
it("skips executing root-level command if builder's help is executed", () => {
const r = checkOutput(() => {
yargs(['blerg', '-h'])
.command(
Expand All @@ -362,7 +362,7 @@ describe('yargs dsl tests', () => {
'handle blerg things',
'',
'Commands:',
' usage snuh snuh command',
' usage blerg snuh snuh command',
'',
'Options:',
' --version Show version number [boolean]',
Expand Down

0 comments on commit cd1ca15

Please sign in to comment.