You're Invited:Meet the Socket Team at RSAC and BSidesSF 2026, March 23–26.RSVP
Socket
Book a DemoSign in
Socket

commander-config

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

commander-config - npm Package Compare versions

Comparing version
0.0.0
to
0.0.1
+12
-2
index.js

@@ -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",

@@ -5,2 +5,44 @@ [![Build Status](https://secure.travis-ci.org/ForbesLindesay/commander-config.png?branch=master)](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) {
}));
```

@@ -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'});
});
});
});