Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(usage): translate 'options' group only when displaying help #1600

Merged
merged 3 commits into from Mar 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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