Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[recovery] Support alternative, and slightly more standard, form #1

Open
ljharb opened this issue Apr 29, 2024 · 0 comments
Open

[recovery] Support alternative, and slightly more standard, form #1

ljharb opened this issue Apr 29, 2024 · 0 comments

Comments

@ljharb
Copy link
Member

ljharb commented Apr 29, 2024

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, then subarg would have to collaborate with subordinate minimist 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 } ]

Response by @ELLIOTTCABLE:

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 }
@ljharb ljharb transferred this issue from another repository May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant