Skip to content

Commit

Permalink
Fix #173 regression on --token (#177)
Browse files Browse the repository at this point in the history
* Fix issue #173 regression

* Adjusted help output for -t and -N overrides

* Removed out-of-scope changes
  • Loading branch information
kurtkanaskie authored and whitlockjc committed Oct 25, 2019
1 parent ba3ac49 commit 48ea26b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
40 changes: 18 additions & 22 deletions lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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)')
]);
});

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 0 additions & 13 deletions test/testoptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down

0 comments on commit 48ea26b

Please sign in to comment.