Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Closes #286 Allow long cli arguments to have both --option=value and

--option value syntax style.
  • Loading branch information...
commit 25c2212e01dfbdfb19e1aa567740c9637bac03e2 1 parent a894fee
@larzconwell larzconwell authored
Showing with 31 additions and 8 deletions.
  1. +31 −8 lib/parseopts.js
View
39 lib/parseopts.js
@@ -96,15 +96,36 @@ parseopts.Parser.prototype = new function () {
argItems = arg.split('=');
argObj = this.longOpts[argItems[0].substr(2)];
- // If argument exists
if (argObj) {
- fullArgName = argObj.full; // Get full name
+ // Args included a space instead of usual = value
+ if (argItems.length === 1) {
+ fullArgName = argObj.full;
- // If the option doesn't rake arguments then set value to true
- if(!argObj.args) {
- opts[fullArgName] = true;
- } else opts[fullArgName] = argItems[1] || true;
- } else throw new Error('Unknown option "' + arg + '"');
+ if (!argObj.args) {
+ opts[fullArgName] = true;
+ } else {
+ // If no argument is given for this option then set it's value to true
+ if(!args[0] || (args[0].indexOf('-') == 0) || (args[0].indexOf('--') == 0)) {
+ opts[fullArgName] = true;
+ } else {
+ opts[fullArgName] = args.shift();
+ }
+ }
+ }
+ else {
+ fullArgName = argObj.full;
+
+ // If the opt doesn't take args then set value to true
+ if (!argObj.args) {
+ opts[fullArgName] = true;
+ } else {
+ opts[fullArgName] = argItems[1] || true;
+ }
+ }
+ }
+ else {
+ throw new Error('Unknown option "' + arg + '"');
+ }
}
// Short option name
else if (arg.indexOf('-') === 0) {
@@ -122,7 +143,9 @@ parseopts.Parser.prototype = new function () {
// If no argument is given for this option then set it's value to true
if(!args[0] || (args[0].indexOf('-') == 0) || (args[0].indexOf('--') == 0)) {
opts[fullArgName] = true;
- } else opts[fullArgName] = args.shift();
+ } else {
+ opts[fullArgName] = args.shift();
+ }
}
} else throw new Error('Unknown option "' + arg + '"');
}
Please sign in to comment.
Something went wrong with that request. Please try again.