diff --git a/TODO.md b/TODO.md index 4fb10c7..dd77911 100644 --- a/TODO.md +++ b/TODO.md @@ -15,6 +15,7 @@ # later (in no particular order) +- restify-client and bunyan-light without dtrace-provider - how to add/exclude DCs? - cmdln.js support for bash tab completion - node-smartdc installs joyentcloud and warns about deprecation on stderr. diff --git a/lib/cli.js b/lib/cli.js index 940e135..dbb3717 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -48,7 +48,9 @@ function CLI() { {names: ['help', 'h'], type: 'bool', help: 'Print help and exit.'}, {name: 'version', type: 'bool', help: 'Print version and exit.'}, {names: ['verbose', 'v'], type: 'bool', - help: 'Verbose/debug output.'} + help: 'Verbose/debug output.'}, + {names: ['profile', 'p'], type: 'string', env: 'SMRT_PROFILE', + helpArg: 'NAME', help: 'SMRT Profile to use.'} ], helpOpts: { includeEnv: true, @@ -73,11 +75,11 @@ CLI.prototype.init = function (opts, args, callback) { log.src = true; } - this.__defineGetter__('joyent', function () { - if (self._joyent === undefined) { - self._joyent = new JoyentCloud({log: log}); + this.__defineGetter__('jc', function () { + if (self._jc === undefined) { + self._jc = new JoyentCloud({log: log, profile: opts.profile}); } - return self._joyent; + return self._jc; }); // Cmdln class handles `opts.help`. @@ -93,11 +95,11 @@ CLI.prototype.do_profile = function (subcmd, opts, args, callback) { return callback(new Error('too many args: ' + args)); } - var profs = common.deepObjCopy(this.joyent.profiles); - var currProfileName = this.joyent.profile.name; + var profs = common.deepObjCopy(this.jc.profiles); + var currProfileName = this.jc.profile.name; for (var i = 0; i < profs.length; i++) { profs[i].curr = (profs[i].name === currProfileName ? '*' : ' '); - profs[i].dcs = (profs[i].dcs ? Object.keys(profs[i].dcs) : ['all']) + profs[i].dcs = (profs[i].dcs ? profs[i].dcs : ['all']) .join(','); } if (opts.json) { @@ -141,7 +143,7 @@ CLI.prototype.do_dcs = function (subcmd, opts, args, callback) { return callback(new Error('too many args: ' + args)); } - var dcs = this.joyent.config.dcs; + var dcs = this.jc.config.dcs; var dcsArray = Object.keys(dcs).map( function (n) { return {name: n, url: dcs[n]}; }); if (opts.json) { @@ -186,14 +188,14 @@ CLI.prototype.do_machines = function (subcmd, opts, args, callback) { return callback(new Error('too many args: ' + args)); } - //XXX joyent.listMachines should change to return a 'res' event emitter + //XXX jc.listMachines should change to return a 'res' event emitter // that emits 'dcError' and 'data'. var listOpts = { onDcError: function (dc, dcErr) { console.warn('%s machines: dc %s error: %s', self.name, dc, dcErr); } }; - this.joyent.listMachines(listOpts, function (err, machines) { + this.jc.listMachines(listOpts, function (err, machines) { if (err) return callback(err); if (opts.json) { diff --git a/lib/config.js b/lib/config.js index c654917..55e7092 100755 --- a/lib/config.js +++ b/lib/config.js @@ -12,7 +12,7 @@ var sprintf = require('extsprintf').sprintf; var common = require('./common'); -var CONFIG_PATH = path.resolve(process.env.HOME, '.joyentconfig.json'); +var CONFIG_PATH = path.resolve(process.env.HOME, '.joyentcloudconfig.json'); var DEFAULTS_PATH = path.resolve(__dirname, '..', 'etc', 'defaults.json'); @@ -26,15 +26,14 @@ function loadConfigSync() { // Add 'env' profile. if (!config.profiles) { config.profiles = []; - config.profiles.push({ - name: 'env', - account: process.env.SDC_USER || process.env.SDC_ACCOUNT, - keyId: process.env.SDC_KEY_ID, - //XXX true/false 0/1 handling - rejectUnauthorized: common.boolFromString( - process.env.SDC_TESTING || process.env.SDC_TLS_INSECURE) - }); } + config.profiles.push({ + name: 'env', + account: process.env.SDC_USER || process.env.SDC_ACCOUNT, + keyId: process.env.SDC_KEY_ID, + rejectUnauthorized: common.boolFromString( + process.env.SDC_TESTING || process.env.SDC_TLS_INSECURE) + }); return config; } diff --git a/lib/joyentcloud.js b/lib/joyentcloud.js index 3f28325..1484f31 100644 --- a/lib/joyentcloud.js +++ b/lib/joyentcloud.js @@ -32,12 +32,11 @@ function JoyentCloud(options) { assert.object(options.log, 'options.log'); assert.optionalString(options.profile, 'options.profile'); + this.log = options.log; this.config = loadConfigSync(); this.profiles = this.config.profiles; this.profile = this.getProfile( options.profile || this.config.defaultProfile); - - this.log = options.log; this.log.trace({profile: this.profile}, 'profile data'); }