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) {
|
function parse(argv) {
|
||||||
argv = process.argv.slice(2);
|
argv = process.argv.slice(2);
|
||||||
|
|
@ -59,7 +59,7 @@ function parse(argv) {
|
||||||
return;
|
return;
|
||||||
});
|
});
|
||||||
|
|
||||||
let out = []
|
let out = {};
|
||||||
grouped.forEach((a, i) => {
|
grouped.forEach((a, i) => {
|
||||||
let next = grouped[i+1];
|
let next = grouped[i+1];
|
||||||
|
|
||||||
|
|
@ -67,17 +67,13 @@ function parse(argv) {
|
||||||
&& next
|
&& next
|
||||||
&& (next[0].type === 'arg_or_operand')) {
|
&& (next[0].type === 'arg_or_operand')) {
|
||||||
let next_shortened = next.map(n => n.arg);
|
let next_shortened = next.map(n => n.arg);
|
||||||
let o = {};
|
out[a[0].arg] = next_shortened;
|
||||||
o[a[0].arg] = next_shortened;
|
|
||||||
out.push(o);
|
|
||||||
grouped.splice(i, 1);
|
grouped.splice(i, 1);
|
||||||
} else {
|
} else {
|
||||||
let pair = {};
|
let pair = {};
|
||||||
pair[a[0].arg] = true;
|
pair[a[0].arg] = true;
|
||||||
a.forEach((b) => {
|
a.forEach((b) => {
|
||||||
let o = {};
|
out[b.arg] = true;
|
||||||
o[b.arg] = true;
|
|
||||||
out.push(o);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue