Skip to content

Commit

Permalink
Merge branch 'master' into release-v15.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Oct 28, 2019
2 parents 0c69dec + cb0396f commit 2e370b3
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Expand Up @@ -15,4 +15,12 @@ cache:
directories:
- "node_modules"

after_success: if [[ "$TRAVIS_OS_NAME" != 'windows' ]]; then npm run coverage; fi
jobs:
include:
- stage: coverage
node_js: "13"
os:
- linux
script:
- npm t
- npm run coverage
4 changes: 2 additions & 2 deletions lib/command.js
Expand Up @@ -79,7 +79,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
description: description,
handler,
builder: builder || {},
middlewares: middlewares || [],
middlewares,
demanded: parsedCommand.demanded,
optional: parsedCommand.optional
}
Expand Down Expand Up @@ -218,7 +218,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
positionalMap = populatePositionals(commandHandler, innerArgv, currentContext, yargs)
}

const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares || [])
const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares)
applyMiddleware(innerArgv, yargs, middlewares, true)

// we apply validation post-hoc, so that custom
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"yargs-parser": "^16.0.0"
},
"devDependencies": {
"c8": "^6.0.1",
"chai": "^4.2.0",
"chalk": "^2.4.2",
"coveralls": "^3.0.3",
Expand All @@ -40,17 +41,17 @@
"es6-promise": "^4.2.5",
"hashish": "0.0.4",
"mocha": "^5.2.0",
"nyc": "^14.1.0",
"rimraf": "^2.6.3",
"standard": "^12.0.1",
"standard-version": "^7.0.0",
"which": "^1.3.1",
"yargs-test-extends": "^1.0.1"
},
"scripts": {
"fix": "standard --fix",
"pretest": "standard",
"test": "nyc --cache mocha --require ./test/before.js --timeout=12000 --check-leaks",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"test": "c8 --reporter=html --reporter=text mocha --require ./test/before.js --timeout=12000 --check-leaks",
"coverage": "c8 report --reporter=text-lcov | coveralls",
"release": "standard-version"
},
"repository": {
Expand Down
12 changes: 6 additions & 6 deletions test/yargs.js
Expand Up @@ -617,6 +617,12 @@ describe('yargs dsl tests', () => {
})

describe('locale', () => {
function loadLocale (locale) {
delete require.cache[require.resolve('../')]
yargs = require('../')
process.env.LC_ALL = locale
}

it('uses english as a default locale', () => {
['LANGUAGE', 'LC_ALL', 'LANG', 'LC_MESSAGES'].forEach((e) => {
delete process.env[e]
Expand Down Expand Up @@ -649,12 +655,6 @@ describe('yargs dsl tests', () => {
loadLocale('en_US.UTF-8')
})

function loadLocale (locale) {
delete require.cache[require.resolve('../')]
yargs = require('../')
process.env.LC_ALL = locale
}

it("allows a locale other than the default 'en' to be specified", () => {
const r = checkOutput(() => {
yargs(['snuh', '-h'])
Expand Down
13 changes: 3 additions & 10 deletions yargs.js
Expand Up @@ -1177,7 +1177,7 @@ function Yargs (processArgs, cwd, parentRequire) {
}

self._runValidation = function runValidation (argv, aliases, positionalMap, parseErrors) {
if (parseErrors) throw new YError(parseErrors.message || parseErrors)
if (parseErrors) throw new YError(parseErrors.message)
validation.nonOptionCount(argv)
validation.requiredArguments(argv)
if (strict) validation.unknownArguments(argv, aliases, positionalMap)
Expand All @@ -1189,15 +1189,8 @@ function Yargs (processArgs, cwd, parentRequire) {

function guessLocale () {
if (!detectLocale) return

try {
const { env } = process
const locale = env.LC_ALL || env.LC_MESSAGES || env.LANG || env.LANGUAGE || 'en_US'
self.locale(locale.replace(/[.:].*/, ''))
} catch (err) {
// if we explode looking up locale just noop
// we'll keep using the default language 'en'.
}
const locale = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || process.env.LANGUAGE || 'en_US'
self.locale(locale.replace(/[.:].*/, ''))
}

// an app should almost always have --version and --help,
Expand Down

0 comments on commit 2e370b3

Please sign in to comment.