pkgjs / parseargs

Polyfill of `util.parseArgs()`
Apache License 2.0
121 stars 9 forks source link

refactor!: parsing, revisit short option groups, add support for combined short and value #75

Closed shadowspawn closed 2 years ago

shadowspawn commented 2 years ago

This incorporates ideas from #64, #68, and #69. Background on short options in #2.

1) Refactor parsing to use independent blocks of code, rather than nested cascading context. This makes it easier to reason about the behaviour.

2) Split out small pieces of logic to named routines to improve readability, and allow extra documentation and examples without cluttering the parsing. (Thanks to @aaronccasanova for inspiration.)

3) Existing tests untouched to make it clear that the tested functionality has not changed.

4) Be more explicit about short option group expansion, and ready to throw error in strict mode for string option in the middle of the argument. (See #11 and #74.)

5) Add support for short option combined with value (without intervening =). This is what Commander and Open Group Utility Conventions do, but is not what Yargs does. I don't want to block PR on this and happy to comment it out for further discussion if needed. (I have found some interesting variations in the wild.) [Edit: see also #78]

6) Add support for multiple unit tests files. Expand tests from 33 to 113, but many for internal routines rather than testing exposed API.

7) Added .editorconfig file, mainly for my own convenience!

shadowspawn commented 2 years ago

I was neglecting the exports from the shim point of view, but makes good sense from the package point of view. Done. Thanks.

shadowspawn commented 2 years ago

8) Added tests for duck-typing of misused options, which came out of discussion in #24 and #25.

shadowspawn commented 2 years ago

Thanks @aaronccasanova , you have picked up several errata in the comments and some good suggestions and questions.

shadowspawn commented 2 years ago

Thanks for reviews and comments @ljharb and @Eomm and @aaronccasanova . I'll wait for @bcoe to at least have a quick look before I consider merging.

Further comments welcome from any gentle readers.

shadowspawn commented 2 years ago

Waiting no longer. 😄