Skip to content

Commit

Permalink
fix(usage): translate 'options' group only when displaying help (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
mleguen committed Mar 27, 2020
1 parent c67c257 commit e60b39b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/usage.js
Expand Up @@ -146,7 +146,6 @@ module.exports = function usage (yargs, y18n) {
const deferY18nLookupPrefix = '__yargsString__:'
self.deferY18nLookup = str => deferY18nLookupPrefix + str

const defaultGroup = __('Options:')
self.help = function help () {
if (cachedHelpMessage) return cachedHelpMessage
normalizeAliases()
Expand Down Expand Up @@ -245,8 +244,9 @@ module.exports = function usage (yargs, y18n) {

// populate 'Options:' group with any keys that have not
// explicitly had a group set.
const defaultGroup = __('Options:')
if (!groups[defaultGroup]) groups[defaultGroup] = []
addUngroupedKeys(keys, options.alias, groups)
addUngroupedKeys(keys, options.alias, groups, defaultGroup)

// display 'Options:' table along with any custom tables:
Object.keys(groups).forEach((groupName) => {
Expand Down Expand Up @@ -433,7 +433,7 @@ module.exports = function usage (yargs, y18n) {

// given a set of keys, place any keys that are
// ungrouped under the 'Options:' grouping.
function addUngroupedKeys (keys, aliases, groups) {
function addUngroupedKeys (keys, aliases, groups, defaultGroup) {
let groupedKeys = []
let toCheck = null
Object.keys(groups).forEach((group) => {
Expand Down
14 changes: 14 additions & 0 deletions test/yargs.js
Expand Up @@ -776,6 +776,20 @@ describe('yargs dsl tests', () => {
r.logs.join(' ').should.match(/COMMANDS!/)
})

it('also works on default option group', () => {
const r = checkOutput(() => {
yargs(['-h'])
.help('h')
.wrap(null)
.updateLocale({
'Options:': 'OPTIONS!'
})
.parse()
})

r.logs.join(' ').should.match(/OPTIONS!/)
})

it('allows you to use updateStrings() as an alias for updateLocale()', () => {
const r = checkOutput(() => {
yargs(['snuh', '-h'])
Expand Down

0 comments on commit e60b39b

Please sign in to comment.