commander-config
Advanced tools
+12
-2
@@ -86,4 +86,14 @@ var path = require('path'); | ||
| lookUpSettings(relativePath).then(function (settings) { | ||
| merge(args[0]).into(settings); | ||
| args[0] = settings; | ||
| var merged = false; | ||
| for (var i = 0; i < args.length; i++) { | ||
| if (typeof args[i] === 'object') { | ||
| if (merged) throw new Error('You can\'t merge settings into two arguments'); | ||
| merge(args[i]).into(settings); | ||
| args[i] = settings; | ||
| merged = true; | ||
| } | ||
| } | ||
| if (!merged) { | ||
| console.warn('Commander config was unable to merge settings.'); | ||
| } | ||
| cb.apply(self, args); | ||
@@ -90,0 +100,0 @@ }).end(); |
+1
-1
| { | ||
| "name": "commander-config", | ||
| "version": "0.0.0", | ||
| "version": "0.0.1", | ||
| "description": "Recursively walks up directories from the current directory to look for settings files to provide defaults for commander.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+43
-1
@@ -5,2 +5,44 @@ [](http://travis-ci.org/ForbesLindesay/commander-config) | ||
| Recursively walks up directories from the current directory to look for settings files to provide defaults for commander.js | ||
| Recursively walks up directories from the current directory to look for settings files to provide defaults for commander.js | ||
| If you run your app in `/foo/bar/baz/` and use the relative path `.boz` then commander-config would try: | ||
| - `/foo/bar/baz/.boz.json` | ||
| - `/foo/bar/baz/.boz.yaml` | ||
| - `/foo/bar/baz/.boz.yml` | ||
| - `/foo/bar/.boz.json` | ||
| - `/foo/bar/.boz.yaml` | ||
| - `/foo/bar/.boz.yml` | ||
| - `/foo/.boz.json` | ||
| - `/foo/.boz.yaml` | ||
| - `/foo/.boz.yml` | ||
| - `/.boz.json` | ||
| - `/.boz.yaml` | ||
| - `/.boz.yml` | ||
| It will then merge any settings it finds such that the ones at the top of that list override the ones at the bottom. | ||
| ## API | ||
| ### lookUpSettings(relativePath) | ||
| Looks up settings relative to the current directory, and relative to each parent directory of the current directory. Child directories take priority over parent directories and the settings are merged in using a shallow merge. The return value is a promise. | ||
| ```javascript | ||
| var settings = require('comander-config').lookUpSettings('.myCrazyApp'); | ||
| settings.then(console.log).end(); | ||
| ``` | ||
| ### withSettings(relativePath, cb) | ||
| When used with commander this will merge settings into the env parameter of the function. | ||
| ```javascript | ||
| var program = require('commander'); | ||
| var config = require('commander-config'); | ||
| program | ||
| .command('run [name]') | ||
| .action(config.withSettings('.myCrazyApp', function (name, env) { | ||
| })); | ||
| ``` |
+14
-2
@@ -26,3 +26,3 @@ var assert = require('should'); | ||
| describe('commander `withSettings`', function () { | ||
| describe('calling the result with a few arguments', function () { | ||
| describe('calling the result with env in first argument', function () { | ||
| it('works as expected', function (done) { | ||
@@ -38,3 +38,15 @@ lib.withSettings('./settings', function (env, command) { | ||
| }); | ||
| }) | ||
| }); | ||
| describe('calling the result with env in second argument', function () { | ||
| it('works as expected', function (done) { | ||
| lib.withSettings('./settings', function (command, env) { | ||
| command.should.equal('command'); | ||
| env.a.should.equal('hello'); | ||
| env.b.should.equal('forbes'); | ||
| env.c.should.equal('foo'); | ||
| env.d.should.equal('bar'); | ||
| done(); | ||
| })('command', {a: 'hello'}); | ||
| }); | ||
| }); | ||
| }); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Non-existent author
Supply chain riskThe package was published by an npm account that no longer exists.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
9427
30.82%228
10.68%47
840%0
-100%1
Infinity%