-
-
Notifications
You must be signed in to change notification settings - Fork 9
Description
https://web.archive.org/web/20201110211134/https://github.com/substack/subarg/issues/1
Filed by @ELLIOTTCABLE
I love the nested
[ . . . ]
form that you've settled on, here. I'd totally be down for using that for tasks like this.However, a pattern I've seen round 'n about, is something like this:
--beep boop --beep -a=3
, with the argument following each invocation of the name being passed through.Concerns: this adds at least one, if not two, new layers of complexity; these need their own, individual consideration:
subarg
would need knowledge of the names of the coming ‘pieces of code’ at parse-time; instead of those being flexible, and simply dropping into an argument-structure. Not Very Minimist™. Maybe there's a way around that.
if the form--beep -a 3
were to be supported, thensubarg
would have to collaborate with subordinateminimist
invocations (to find out if -a consumes the forthcoming 3, presumably), which comes damn close to defeating the point. Luckily, I feel like that's an edge case, and forcing the-a=3
or-a3
instead of-a 3
is an acceptable compromise.
Perhaps not something to attack just yet; instead, an observation.
Response by @substack:
What about just taking a module that does a generic array split and then feeding the chunks into minimist to accomplish this?
update: turns out I already wrote a generic array splitting library 2 years ago: https://github.com/substack/node-split-by
var split = require('split-by'); var minimist = require('minimist'); var parts = split(process.argv.slice(2), [ '--beep' ]); var beeps = parts.map(minimist); console.log(beeps);
output:
$ node arg.js --beep 3 -a 5 --beep x y -b 2 -z [ { _: [] }, { _: [ 3 ], a: 5 }, { _: [ 'x', 'y' ], b: 2, z: true } ]
Er, that's not at all what I was suggesting (although a very similar approach to yours obviously makes this use-case pretty easy to simulate on the consumer's side):
$ node arg.js --beep 3 -a 5 --beep x y -b 2 -z [ { _: ['y'], a: 5, b: 2, z: true }, { _: [ 3, 'x' ] } ]
Response by @substack:
I'm not sure what the use-case is then. If you have multiple
--beep
args they will already show up as an array:$ node example/parse.js --beep x 1 2 --beep y 3 4 -z { _: [ 1, 2, 3, 4 ], beep: [ 'x', 'y' ], z: true }