Open banli17 opened 3 years ago
same question。Did you solve it?
I also had this problem then I looked at all the options and if I understood correctly we need to tell the parser that we want it to be converted to array by using the array
option as follow
const args = parser(process.argv.slice(2), {
array: ['--foo', 'apple', 'banana', 'cat'],
configuration: {
"greedy-arrays": true
}
})
so I basically pass the arguments array to both the first argument and also to the array
property and now it works, not exactly trivial
Isn't the correct way just:
parser(process.argv.slice(2), {
array: ['foo'],
})
cli --foo apple banana cat
I.e. you still need to tell the parser whether to treat an option as an array, before greedy parsing even comes into play. And greedy-arrays
are already true by default (as of v21)
@banli17 I see you asked the same question in #372. I hope the above answers it.
how to get
{ _: [ ], foo: ['apple', 'banana', 'cat' ] }
Instead of specifying array: ['foo'],