cli-argparse
Advanced tools
Comparing version
22
index.js
var short = '-', long = '--'; | ||
var sre = /^-[^-]+/, lre = /^--[^-]+/, negate = /^--no-/; | ||
var sre = /^-[^-]+/, lre = /^--[^-]+/, negate = /--no-/; | ||
var camelcase = require('cli-util').camelcase; | ||
@@ -17,3 +17,4 @@ | ||
keys = z.split(/\s+/); | ||
if(keys.indexOf(key) > -1) return {key: alias[z], aliased: true, negated: /--no-/.test(z)}; | ||
if(~keys.indexOf(key)) return {key: alias[z], | ||
aliased: true, negated: negate.test(z)}; | ||
} | ||
@@ -25,11 +26,10 @@ return {key: key, aliased: false}; | ||
var result = alias(arg, opts), keys, skip = false, i = 0, key, v = true; | ||
if(result.aliased) output.flags[result.key] = true; | ||
if(result.aliased) output.flags[result.key] = v; | ||
arg = arg.replace(/^-/, ''); keys = arg.split(''); | ||
for(;i < keys.length;i++, key = keys[i]) { | ||
key = keys[i]; | ||
if(i == keys.length - 1 && opts.options.indexOf(short + key) > -1) { | ||
if(i == keys.length - 1 && ~opts.options.indexOf(short + key)) { | ||
return options(short + key, output, next, opts); | ||
} | ||
result = alias(short + key, opts); | ||
// short option flag has an alias component that negates (--no-) | ||
if(result.negated) v = false; | ||
@@ -43,9 +43,9 @@ output.flags[result.aliased ? result.key : key] = v; | ||
var equals = arg.indexOf('='), value, result = false, negated, key; | ||
var flag = (!next && equals == -1) | ||
|| (next && next.indexOf(short) == 0 && equals == -1); | ||
if(equals > -1) { | ||
var flag = (!next && !~equals) | ||
|| (next && next.indexOf(short) == 0 && !~equals); | ||
if(~equals) { | ||
value = arg.slice(equals + 1); arg = arg.slice(0, equals); | ||
} | ||
if(opts.flags.indexOf(arg) > -1) flag = true; | ||
if(next && !flag && equals == -1) { | ||
if(~opts.flags.indexOf(arg)) flag = true; | ||
if(next && !flag && !~equals) { | ||
value = next; result = true; | ||
@@ -82,3 +82,3 @@ } | ||
opts.options.forEach(function(o){ | ||
if(arg.indexOf(o) > -1) larg = true; | ||
if(~arg.indexOf(o)) larg = true; | ||
}); | ||
@@ -85,0 +85,0 @@ if(arg == short) { |
{ | ||
"name": "cli-argparse", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Lightweight argument parser", | ||
@@ -5,0 +5,0 @@ "author": "muji <noop@xpm.io>", |
7382
-1.34%