Skip to content

Commit

Permalink
fix: show hidden options in help
Browse files Browse the repository at this point in the history
Options with `description: false` will now show up help
  • Loading branch information
laggingreflex committed Sep 27, 2017
1 parent d1b23f3 commit 31b784e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/usage.js
Expand Up @@ -138,6 +138,7 @@ module.exports = function usage (yargs, y18n) {
.concat(Object.keys(demandedOptions))
.concat(Object.keys(demandedCommands))
.concat(Object.keys(options.default))
.concat(options.hiddenOptions)
.reduce((acc, key) => {
if (key !== '_') acc[key] = true
return acc
Expand Down
30 changes: 30 additions & 0 deletions test/usage.js
Expand Up @@ -2523,4 +2523,34 @@ describe('usage tests', () => {
])
})
})

describe('hidden options', () => {
it('--help should not display options without description', () => {
const r = checkUsage(() => yargs('--help')
.option('someOption')
.argv
)

r.logs[0].split('\n').should.deep.equal([
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
''
])
})
it('--help should display options with description=false', () => {
const r = checkUsage(() => yargs('--help')
.option('someOption', {description: false})
.argv
)

r.logs[0].split('\n').should.deep.equal([
'Options:',
' --help Show help [boolean]',
' --version Show version number [boolean]',
' --someOption',
''
])
})
})
})
1 change: 1 addition & 0 deletions test/yargs.js
Expand Up @@ -246,6 +246,7 @@ describe('yargs dsl tests', () => {
config: {},
configObjects: [],
envPrefix: 'YARGS', // preserved as global
hiddenOptions: [],
demandedCommands: {},
demandedOptions: {},
local: [
Expand Down
14 changes: 12 additions & 2 deletions yargs.js
Expand Up @@ -92,7 +92,8 @@ function Yargs (processArgs, cwd, parentRequire) {

const arrayOptions = [
'array', 'boolean', 'string', 'requiresArg', 'skipValidation',
'count', 'normalize', 'number'
'count', 'normalize', 'number',
'hiddenOptions'
]

const objectOptions = [
Expand Down Expand Up @@ -644,9 +645,18 @@ function Yargs (processArgs, cwd, parentRequire) {
self.skipValidation(key)
}

const desc = opt.describe || opt.description || opt.desc
let desc;
if ('describe' in opt) {
desc = opt.describe
} else if ('description' in opt) {
desc = opt.description
} else if ('desc' in opt) {
desc = opt.desc
}
if (desc) {
self.describe(key, desc)
} else if (desc === false) {
options.hiddenOptions.push(key)
}

if (opt.requiresArg) {
Expand Down

0 comments on commit 31b784e

Please sign in to comment.