From 1b2ed0758e1067fb48c8b34c117ed4009fac5f82 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Mon, 31 Aug 2015 12:23:20 -0700 Subject: [PATCH] Fix handling of SDC_TESTING envvar --- lib/cli.js | 8 ++++++-- lib/common.js | 9 ++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 14f768e..40cbce8 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -198,8 +198,12 @@ CLI.prototype.init = function (opts, args, callback) { keyId: opts.keyId, insecure: opts.insecure }; - if (opts.insecure === undefined && process.env.SDC_TESTING) { - opts.insecure = common.boolFromString(process.env.SDC_TESTING); + // If --insecure not given, look at envvar(s) for that. + var specifiedInsecureOpt = opts._order.filter( + function (opt) { return opt.key === 'insecure'; }).length > 0; + if (!specifiedInsecureOpt && process.env.SDC_TESTING) { + opts.insecure = common.boolFromString(process.env.SDC_TESTING, + false, '"SDC_TESTING" envvar'); } if (opts.J) { envProfile.url = format('https://%s.api.joyent.com', opts.J); diff --git a/lib/common.js b/lib/common.js index ca5065f..7c77f05 100755 --- a/lib/common.js +++ b/lib/common.js @@ -50,7 +50,7 @@ function zeroPad(n, width) { * * @param value {Boolean|String} The input value to convert. * @param default_ {Boolean} The default value is `value` is undefined. - * @param errName {String} The variable name to quote in the possibly + * @param errName {String} The context to quote in the possibly * raised TypeError. */ function boolFromString(value, default_, errName) { @@ -63,8 +63,11 @@ function boolFromString(value, default_, errName) { } else if (typeof (value) === 'boolean') { return value; } else { - throw new TypeError( - format('invalid value for "%s": %j', errName, value)); + var errmsg = format('invalid boolean value: %j', value); + if (errName) { + errmsg = format('invalid boolean value for %s: %j', errName, value); + } + throw new TypeError(errmsg); } }