Skip to content

Commit

Permalink
Merge pull request #12 from evocateur/argv-param
Browse files Browse the repository at this point in the history
Allow optional non-Optimist argv.
  • Loading branch information
dominictarr committed May 19, 2013
2 parents 95b397c + 61562bd commit 155b851
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#! /usr/bin/env node
var argv = require('optimist').argv
var cc = require('./lib/utils')
var join = require('path').join
var deepExtend = require('deep-extend')
Expand All @@ -9,9 +8,11 @@ var home = win
? process.env.USERPROFILE
: process.env.HOME

module.exports = function (name, defaults) {
module.exports = function (name, defaults, argv) {
if(!name)
throw new Error('nameless configuration fail')
if(!argv)
argv = require('optimist').argv
defaults = (
'string' === typeof defaults
? cc.json(defaults) : defaults
Expand Down
17 changes: 17 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ console.log(config)

assert.equal(config.option, true)
assert.equal(config.envOption, 42)

var customArgv = require('../')(n, {
option: true
}, { // nopt-like argv
option: false,
envOption: 24,
argv: {
remain: [],
cooked: ['--no-option', '--envOption', '24'],
original: ['--no-option', '--envOption=24']
}
})

console.log(customArgv)

assert.equal(customArgv.option, false)
assert.equal(customArgv.envOption, 24)

0 comments on commit 155b851

Please sign in to comment.