Permalink
Browse files

Use config file branch of optimist.

  • Loading branch information...
1 parent 52855d2 commit 69a1f9b0941bb0faa616d5fe360b947a91bacb25 @willwhite willwhite committed Mar 11, 2013
Showing with 10 additions and 18 deletions.
  1. +8 −17 index.js
  2. +2 −1 package.json
View
@@ -19,7 +19,8 @@ var optimist = require('optimist')
.describe('filter', 'Applies a filter to results based on EC2 instance attributes and tags. Use `filter.<attributeName>`. Multiple filters are applied with the AND operator. Required for the classify command and optional for the metadata command.')
.describe('awsKey', 'awsKey, overrides the value in gconfig file if both are provided.')
.describe('awsSecret', 'awsSecret, overrides the value in config file if both are provided.')
- .default('regions', 'us-east-1,us-west-1,us-west-2,eu-west-1,ap-southeast-1,ap-northeast-1,sa-east-1');
+ .default('regions', 'us-east-1,us-west-1,us-west-2,eu-west-1,ap-southeast-1,ap-northeast-1,sa-east-1')
+ .config('config');
var argv = optimist.argv;
if (argv.help) {
@@ -47,28 +48,18 @@ if (command === 'metadata' && !argv.attribute) {
process.exit(1);
}
-var config = {};
-if (argv.config) {
- try {
- config = JSON.parse(fs.readFileSync(argv.config, 'utf8'));
- } catch(e) {
- console.warn('Invalid JSON config file: ' + argv.config);
- throw e;
- }
-}
-
var regions = argv.regions.split(',');
-if (argv.awsKey) config.awsKey = argv.awsKey;
-if (argv.awsSecret) config.awsSecret= argv.awsSecret;
+if (argv.awsKey) argv.awsKey = argv.awsKey;
+if (argv.awsSecret) argv.awsSecret= argv.awsSecret;
var swarm = {};
// List
swarm.list = function() {
Step(function() {
var filters = {'resource-type': 'instance'};
- ec2Api.loadTags(ec2Api.createClients(config, regions), filters, this);
+ ec2Api.loadTags(ec2Api.createClients(argv, regions), filters, this);
}, function(err, tags) {
if (err) throw err;
var swarms = _(tags).chain()
@@ -81,7 +72,7 @@ swarm.list = function() {
swarm.metadata = function() {
Step(function() {
- ec2Api.loadInstances(ec2Api.createClients(config, regions), argv.filter, this);
+ ec2Api.loadInstances(ec2Api.createClients(argv, regions), argv.filter, this);
}, function(err, instances) {
if (err) throw err;
var possibleAttr = _(instances).chain()
@@ -118,7 +109,7 @@ swarm.metadata = function() {
//
swarm.classify = function() {
Step(function() {
- ec2Api.loadInstances(ec2Api.createClients(config, regions), argv.filter, this);
+ ec2Api.loadInstances(ec2Api.createClients(argv, regions), argv.filter, this);
}, function(err, instances) {
if (err) throw err;
var instance = _(instances).first();
@@ -163,7 +154,7 @@ Step(function() {
if (err) throw (err);
if (tagCache) return this(null, tagCache);
var filters = {'resource-type': 'instance', 'resource-id': id};
- ec2Api.loadTags(ec2Api.createClients(config, [az.region]), filters, this);
+ ec2Api.loadTags(ec2Api.createClients(argv, [az.region]), filters, this);
}, function(err, tags) {
if (err) return group(err);
tagCache = tags;
View
@@ -17,7 +17,8 @@
"optimist": "0.3.x",
"step": "0.0.x",
"get": "1.1.x",
- "yamlish": "0.0.x"
+ "yamlish": "0.0.x",
+ "optimist": "https://github.com/willwhite/node-optimist/tarball/config-file"
},
"devDependencies": {}
}

0 comments on commit 69a1f9b

Please sign in to comment.