optimist-config-file
Extends optimist with support for JSON/YAML config file Edit
Last updated 4 years ago by macbre .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install optimist-config-file 
SYNC missed versions from official npm registry.

optimist-config-file npm version Build Status

Extends optimist npm module with support for JSON/YAML config file and Docker's inspired environment variables handling.

How to use it

Refer to examples/example.js

npm install --save optimist-config-file
const program = require('optimist-config-file');

program
	.usage('...')
	// ...
	.describe('config', 'uses JSON or YAML-formatted config file to set parameters').string('config');

// handle --config option for passing YAML/JSON config files
program.setConfigFile('config');

// allow env variables to be passed
program.setReplacementVars(process.env);

// parse options
const options = program.parse(process.argv);

console.log(options);

Example

YAML config file:

banner: Hello, ${USERNAME}! Greetings from ${HOSTNAME:-The Unknown Machine}.

Invocations with environment variables and options:

./example.js  --config config.yaml
Hello, macbre! Greetings from The Unknown Machine.

HOSTNAME=`hostname` ./example.js  --config config.yaml
Hello, macbre! Greetings from debian.

./example.js  --config config.yaml --banner='foo'
Hello, macbre! Greetings from The Unknown Machine.

As you can see config file values have precedence over command line ones.

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

2 Versions

  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (4)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |