From 48ea26b69c645180e0d94fedab546fd2a7506bd6 Mon Sep 17 00:00:00 2001 From: Kurt Kanaskie Date: Fri, 25 Oct 2019 15:20:58 -0400 Subject: [PATCH] Fix #173 regression on --token (#177) * Fix issue #173 regression * Adjusted help output for -t and -N overrides * Removed out-of-scope changes --- lib/options.js | 40 ++++++++++++++++++---------------------- package-lock.json | 2 +- test/testoptions.js | 13 ------------- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/lib/options.js b/lib/options.js index 8dc0da4..095e4b6 100644 --- a/lib/options.js +++ b/lib/options.js @@ -125,33 +125,29 @@ module.exports.validate = function(opts, descriptor, cb) { function checkProperty(opts, descriptor, propName, done) { var desc = descriptor[propName]; - // console.log( "DEBUG " + desc.required + " " + opts[propName] + " " + opts.prompt + " " + desc.prompt + " " + propName); - // console.log( "DEBUG OPTs" + JSON.stringify(opts) ); + // console.log( "DEBUG COND " + propName + " " + desc.required + " " + !opts[propName] + " " + !opts.prompt + " " + desc.prompt); + // console.log( "DEBUG OPTs" + JSON.stringify(opts) + "\n"); if (desc === null || desc === undefined) { done(new Error(util.format('Invalid property %s', propName))); return; } - if (desc.required && !opts[propName]) { - if (desc.prompt && !opts.prompt ) { - if (opts.interactive) { - var pn = (desc.name ? desc.name : propName); - prompt(pn, desc.secure, function(err, val) { - if (err) { - done(err); + if (desc.required && !opts[propName] && (!opts.prompt && desc.prompt)) { + if (opts.interactive) { + var pn = (desc.name ? desc.name : propName); + prompt(pn, desc.secure, function(err, val) { + if (err) { + done(err); + } else { + if (desc.secure === true) { + opts[propName] = new SecureValue(val); } else { - if (desc.secure === true) { - opts[propName] = new SecureValue(val); - } else { - opts[propName] = val; - } - done(); + opts[propName] = val; } - }); - } else { - done(new Error(util.format('Missing required option "%s"', propName))); - } + done(); + } + }); } else { - done(new Error(util.format('Missing required option with no prompt "%s"', propName))); + done(new Error(util.format('Missing required option "%s"', propName))); } } else { if (opts[propName] && (desc.secure === true)) { @@ -217,9 +213,9 @@ module.exports.getHelp = function(descriptor) { tab.push([ d[0], (d[1].shortOption ? '-' + d[1].shortOption : ''), - ((d[1].required && !d[1].prompt) ? '(required)': '(optional)'), + ((d[1].required) ? '(required)': '(optional)'), ((d[1].name ? d[1].name : 'undefined')), - ((d[1].scope == 'default') ? '' : '(command specific)') + ((d[1].scope == 'default') ? ((d[1].shortOption == 't' || d[1].shortOption == 'N') ? '(overrides -p/-u)' : '') : '(command specific)') ]); }); diff --git a/package-lock.json b/package-lock.json index 374be77..c62a2ca 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "apigeetool", - "version": "0.13.0", + "version": "0.14.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/test/testoptions.js b/test/testoptions.js index 6ce2a13..62b7671 100644 --- a/test/testoptions.js +++ b/test/testoptions.js @@ -52,19 +52,6 @@ describe('Options parsing test', function() { }); }); - it('Test missing option prompt false', function(done) { - var desc = { - foo: {}, - ping: { required: false, prompt: false }, - pong: { required: true, prompt: false } - }; - var opts = { foo: 1, ping: 1}; - options.validate(opts, desc, function(err) { - assert(err); - assert(/Missing required option/.test(err.message)); - done(); - }); - }); it('Test nothing and missing stuff', function(done) { var desc = { foo: {},