Fix: Return an object instead of an array, so that it's easy to read values of specific options
This commit is contained in:
parent
86e16a9855
commit
5b3cac5103
12
argparser.js
12
argparser.js
|
|
@ -13,7 +13,7 @@ module.exports = parse;
|
|||
|
||||
|
||||
/**
|
||||
* @returns [ { string: boolean } | { string: string[] } ]
|
||||
* @returns [ string: (boolean | string[]) ]
|
||||
**/
|
||||
function parse(argv) {
|
||||
argv = process.argv.slice(2);
|
||||
|
|
@ -59,7 +59,7 @@ function parse(argv) {
|
|||
return;
|
||||
});
|
||||
|
||||
let out = []
|
||||
let out = {};
|
||||
grouped.forEach((a, i) => {
|
||||
let next = grouped[i+1];
|
||||
|
||||
|
|
@ -67,17 +67,13 @@ function parse(argv) {
|
|||
&& next
|
||||
&& (next[0].type === 'arg_or_operand')) {
|
||||
let next_shortened = next.map(n => n.arg);
|
||||
let o = {};
|
||||
o[a[0].arg] = next_shortened;
|
||||
out.push(o);
|
||||
out[a[0].arg] = next_shortened;
|
||||
grouped.splice(i, 1);
|
||||
} else {
|
||||
let pair = {};
|
||||
pair[a[0].arg] = true;
|
||||
a.forEach((b) => {
|
||||
let o = {};
|
||||
o[b.arg] = true;
|
||||
out.push(o);
|
||||
out[b.arg] = true;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue