Skip to content

Commit 3f0746c

Browse files
faressoftbcoe
authored andcommitted
fix: remove the trailing white spaces from the help output (#1090)
BREAKING CHANGE: tests that assert against help output will need to be updated
1 parent ead118a commit 3f0746c

5 files changed

Lines changed: 90 additions & 163 deletions

File tree

lib/usage.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ module.exports = function usage (yargs, y18n) {
4545
// don't output failure message more than once
4646
if (!failureOutput) {
4747
failureOutput = true
48-
if (showHelpOnFail) yargs.showHelp('error')
48+
if (showHelpOnFail) {
49+
yargs.showHelp('error')
50+
logger.error()
51+
}
4952
if (msg || err) logger.error(msg || err)
5053
if (failMessage) {
5154
if (msg || err) logger.error('')
@@ -346,7 +349,8 @@ module.exports = function usage (yargs, y18n) {
346349
ui.div(`${e}\n`)
347350
}
348351

349-
return ui.toString()
352+
// Remove the trailing white spaces
353+
return ui.toString().replace(/\s*$/, '')
350354
}
351355

352356
// return the maximum width of a string

test/command.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,7 @@ describe('Command', () => {
519519
' usage dream [command] [opts] Go to sleep and dream',
520520
'Options:',
521521
' --help Show help [boolean]',
522-
' --version Show version number [boolean]',
523-
''
522+
' --version Show version number [boolean]'
524523
])
525524
})
526525

@@ -541,8 +540,7 @@ describe('Command', () => {
541540
' --help Show help [boolean]',
542541
' --version Show version number [boolean]',
543542
' --shared Is the dream shared with others? [boolean]',
544-
' --extract Attempt extraction? [boolean]',
545-
''
543+
' --extract Attempt extraction? [boolean]'
546544
])
547545
})
548546

@@ -562,8 +560,7 @@ describe('Command', () => {
562560
' usage dream [command] [opts] Go to sleep and dream',
563561
'Options:',
564562
' --help Show help [boolean]',
565-
' --version Show version number [boolean]',
566-
''
563+
' --version Show version number [boolean]'
567564
])
568565
})
569566

@@ -593,8 +590,7 @@ describe('Command', () => {
593590
r.logs.join('\n').split(/\n+/).should.deep.equal([
594591
'Options:',
595592
' --help Show help [boolean]',
596-
' --version Show version number [boolean]',
597-
''
593+
' --version Show version number [boolean]'
598594
])
599595
})
600596

@@ -610,8 +606,7 @@ describe('Command', () => {
610606
'Attempts to (re)apply its own dir',
611607
'Options:',
612608
' --help Show help [boolean]',
613-
' --version Show version number [boolean]',
614-
''
609+
' --version Show version number [boolean]'
615610
])
616611
})
617612

@@ -628,8 +623,7 @@ describe('Command', () => {
628623
' usage nameless Command name derived from module filename',
629624
'Options:',
630625
' --help Show help [boolean]',
631-
' --version Show version number [boolean]',
632-
''
626+
' --version Show version number [boolean]'
633627
])
634628
})
635629
})
@@ -684,17 +678,15 @@ describe('Command', () => {
684678
' command cmd sub Run the subcommand',
685679
'Options:',
686680
' --help Show help [boolean]',
687-
' --version Show version number [boolean]',
688-
''
681+
' --version Show version number [boolean]'
689682
]
690683

691684
const expectedSub = [
692685
'command cmd sub',
693686
'Run the subcommand',
694687
'Options:',
695688
' --help Show help [boolean]',
696-
' --version Show version number [boolean]',
697-
''
689+
' --version Show version number [boolean]'
698690
]
699691

700692
// no help is output if help isn't last

0 commit comments

Comments
 (0)