Skip to content

Commit

Permalink
fix: remove the trailing white spaces from the help output (#1090)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: tests that assert against help output will need to be updated
  • Loading branch information
faressoft authored and bcoe committed Apr 7, 2018
1 parent ead118a commit 3f0746c
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 163 deletions.
8 changes: 6 additions & 2 deletions lib/usage.js
Expand Up @@ -45,7 +45,10 @@ module.exports = function usage (yargs, y18n) {
// don't output failure message more than once
if (!failureOutput) {
failureOutput = true
if (showHelpOnFail) yargs.showHelp('error')
if (showHelpOnFail) {
yargs.showHelp('error')
logger.error()
}
if (msg || err) logger.error(msg || err)
if (failMessage) {
if (msg || err) logger.error('')
Expand Down Expand Up @@ -346,7 +349,8 @@ module.exports = function usage (yargs, y18n) {
ui.div(`${e}\n`)
}

return ui.toString()
// Remove the trailing white spaces
return ui.toString().replace(/\s*$/, '')
}

// return the maximum width of a string
Expand Down
24 changes: 8 additions & 16 deletions test/command.js
Expand Up @@ -519,8 +519,7 @@ describe('Command', () => {
' usage dream [command] [opts] Go to sleep and dream',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
])
})

Expand All @@ -541,8 +540,7 @@ describe('Command', () => {
' --help Show help [boolean]',
' --version Show version number [boolean]',
' --shared Is the dream shared with others? [boolean]',
' --extract Attempt extraction? [boolean]',
''
' --extract Attempt extraction? [boolean]'
])
})

Expand All @@ -562,8 +560,7 @@ describe('Command', () => {
' usage dream [command] [opts] Go to sleep and dream',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
])
})

Expand Down Expand Up @@ -593,8 +590,7 @@ describe('Command', () => {
r.logs.join('\n').split(/\n+/).should.deep.equal([
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
])
})

Expand All @@ -610,8 +606,7 @@ describe('Command', () => {
'Attempts to (re)apply its own dir',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
])
})

Expand All @@ -628,8 +623,7 @@ describe('Command', () => {
' usage nameless Command name derived from module filename',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
])
})
})
Expand Down Expand Up @@ -684,17 +678,15 @@ describe('Command', () => {
' command cmd sub Run the subcommand',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
]

const expectedSub = [
'command cmd sub',
'Run the subcommand',
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
' --version Show version number [boolean]'
]

// no help is output if help isn't last
Expand Down

0 comments on commit 3f0746c

Please sign in to comment.