Skip to content

Commit

Permalink
fix: config and normalise can be disabled with false (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentsnook authored and Morishiri committed Sep 26, 2017
1 parent c649415 commit 3bb8771
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
22 changes: 22 additions & 0 deletions test/yargs.js
Expand Up @@ -1186,6 +1186,17 @@ describe('yargs dsl tests', () => {
argv.foo.should.equal('baz')
})

it('can be disabled with option shorthand', () => {
const argv = yargs('--config ./test/fixtures/config.json')
.option('config', {
config: false,
global: false
})
.argv

argv.config.should.equal('./test/fixtures/config.json')
})

it('allows to pass a configuration object', () => {
const argv = yargs
.config({foo: 1, bar: 2})
Expand Down Expand Up @@ -1285,6 +1296,17 @@ describe('yargs dsl tests', () => {
argv.path = '/foo/bar//baz/asdf/quux/..'
argv.path.should.equal(['', 'foo', 'bar', 'baz', 'asdf'].join(path.sep))
})

it('can be disabled with option shorthand', () => {
const argv = yargs('--path /batman')
.option('path', {
normalize: false
})
.argv

argv.path = 'mongodb://url'
argv.path.should.equal('mongodb://url')
})
})

describe('narg', () => {
Expand Down
10 changes: 5 additions & 5 deletions yargs.js
Expand Up @@ -572,10 +572,6 @@ function Yargs (processArgs, cwd, parentRequire) {
self.demandOption(key, typeof opt.demandOption === 'string' ? opt.demandOption : undefined)
}

if ('config' in opt) {
self.config(key, opt.configParser)
}

if ('conflicts' in opt) {
self.conflicts(key, opt.conflicts)
}
Expand All @@ -592,7 +588,11 @@ function Yargs (processArgs, cwd, parentRequire) {
self.nargs(key, opt.nargs)
}

if ('normalize' in opt) {
if (opt.config) {
self.config(key, opt.configParser)
}

if (opt.normalize) {
self.normalize(key)
}

Expand Down

0 comments on commit 3bb8771

Please sign in to comment.