minimistjs / minimist

parse argument options
MIT License
515 stars 30 forks source link

Add function to turn parsed options back into an argv array #26

Closed curiousdannii closed 1 year ago

curiousdannii commented 1 year ago

It might be out of scope, but it would be helpful to have a function that would turn minimist's parsed options back into an argv array.

ljharb commented 1 year ago

How would that be different than process.argv?

curiousdannii commented 1 year ago

The options may not have originated in process.argv. Or in my case, I'm thinking of a script that parses its process.argv options, modifies or removes some of them, and then calls another program with the result.

Completely fine if it's out of scope, but as I'm already using minimist I thought it would be worth asking. (And no one had previously asked, though I now see that's because all the old issues were lost when the old repo was deleted.)

ljharb commented 1 year ago

Certainly minimist could hold on to the original arg string it's given, and provide it back out somehow - but I think serializing a parsed object into an argument string is a very complex task, and would need to be able to understand all of minimist's options.

Are there any other argument parsing tools that provide this functionality?

curiousdannii commented 1 year ago

Sure thing.

I haven't looked into any alternatives yet. There are a lot of other arg parsers on npm so probably one of them would support it. Thanks!

ljharb commented 1 year ago

Oh, I didn't mean "go use those" :-) i meant, is there any prior art to look at.

Please feel free to reopen after you've looked into it!

shadowspawn commented 1 year ago

I am aware of a couple of implementations, the first of which looks like just what you are asking for:

ljharb commented 1 year ago

If it's relatively lightweight to bring in dargs' functionality to minimist - especially since dargs is ESM-only now, and thus unusable - that's worth considering.

curiousdannii commented 1 year ago

A link in the readme would probably be enough.

ljharb commented 1 year ago

I don't think it'd be a good idea to endorse any package that has moved to ESM-only, even tacitly with a link.

curiousdannii commented 1 year ago

Hah, I'm on-board with ESM, but I wouldn't want to argue it. Do whatever you feel is best! :)

ljharb commented 1 year ago

Any package that can be (synchronously) consumed by both of node's module systems is great! That includes CJS-only, and dual packages. It's only ESM-only packages that are harmful by excluding the majority of the ecosystem.