Skip to content

Commit

Permalink
fix: don't load config when processing positionals
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Coe committed Nov 10, 2018
1 parent 128f322 commit 5d0dc92
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 39 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -4,6 +4,7 @@ node_js:
- "6"
- "8"
- "10"
- "node"

os:
- linux
Expand Down
38 changes: 0 additions & 38 deletions appveyor.yml

This file was deleted.

1 change: 1 addition & 0 deletions lib/command.js
Expand Up @@ -331,6 +331,7 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
options.default = Object.assign(parseOptions.default, options.default)
options.alias = Object.assign(parseOptions.alias, options.alias)
options.array = options.array.concat(parseOptions.array)
delete options.config // don't load config when processing positionals.

const unparsed = []
Object.keys(positionalMap).forEach((key) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
"string-width": "^2.0.0",
"which-module": "^2.0.0",
"y18n": "^3.2.1 || ^4.0.0",
"yargs-parser": "^11.0.0"
"yargs-parser": "^11.1.0"
},
"devDependencies": {
"chai": "^4.1.2",
Expand Down
25 changes: 25 additions & 0 deletions test/command.js
Expand Up @@ -110,6 +110,31 @@ describe('Command', () => {
argv.file.should.equal('foo.js')
argv.reporter.should.equal('html')
})

// bug reported by @boneskull during mocha migration.
it('does not load config twice when command executed', () => {
let parseCount = 0
yargs('cmd --config=.foo.json')
.command(
'$0 [foo..]',
'does a thing',
yargs =>
yargs
.option('config', {
default: '.foo.json'
})
.positional('foo', {
description: 'bar'
})
.config('config', filepath => {
parseCount++
return {}
}),
argv => {}
)
.parse()
parseCount.should.equal(1)
})
})

describe('variadic', () => {
Expand Down

0 comments on commit 5d0dc92

Please sign in to comment.