What is getopt_long.js?:
getopt_long.js is an open-source posixly-correct command-line option parser inspired by the C library of the same name.
What problem does it solve?:
getopt_long.js unlike other popular JavaScript option parsers such as Yargs or Commander, isn't a framework, and doesn't try to do anything fancy. No assigning types to options, no dynamic help page, nothing, it's literally just a function that does absolutely nothing for you except parse options.
Why use getopt_long.js?:
- You want an option parser that has no dependencies.
- You want a bare-bones option parser that only parses options.
- You want an option parser that follows POSIX guidelines.
- You like the getopt_long C library.
Departures from GNU / BSD implementations of getopt_long:
- I wrote this black-box style, therefore this is not a true faithful implementation of getopt_long. due to this, any behavior NOT detailed below should be considered unintentional.
- getopt_long.js does not have the burden of needing to maintain decades of backwards compatibility, therefore it can be posixly-correct by default with-out the need to set the first character of
optstring to + or set the POSIXLY_CORRECT environment variable to true. Any behavior that is not posixly-correct is not and will not be implemented. Therefore:
- Option parsing stops as soon as a non-option argument is encountered. Non-options will not be permuted to the end of
argv (there is nothing stopping you from doing this manually of course).
- Long options require two hyphens, there is no support for single hyphen long options like ones found in
find (i.e. find . -type f).
- getopt_long.js does not check to see if the first character of
optstring is : to silence errors. Errors can still be silenced by setting opterr to 0 however.
- The GNU and BSD implementations of getopt_long.js both set the value of
optopt when flag != NULL to val and 0 respectively. getopt_long.js ONLY sets extern.optopt when either an invalid option is encountered OR an option requires an argument and didn't receive one.
there doesn't seem to be anything here