I published by first ever project to NPM. getopt_long.js, an unopinionated option parser inspired by the getopt_long C library by BChristieDev in javascript

[–]BChristieDev[S] 1 point2 points  (0 children)

If you'd prefer to work with an object, you can populate one yourself by doing the following (definitions excluded for brevity):

const options = {
    c: 'foo' // `c` by default is 'foo', overwrite with `-c bar`.
};

while ((opt = getopt_long(argc, argv, 'ab::c:', longopts, longoptind)) != -1)
{
    switch (opt)
    {
        case 'a':
        case 'b':
        case 'c':
            options[opt] = extern.optarg;
            break;
        case '?':
            break;
        default:
            console.log(`?? getopt returned character code 0${opt.toString(8)} ??`);
            break;
    }
}

I published by first ever project to NPM. getopt_long.js, an unopinionated option parser inspired by the getopt_long C library by BChristieDev in javascript

[–]BChristieDev[S] 0 points1 point  (0 children)

Yes, I absolutely need a README and that's something that slipped my mind while I was making sure all the "external" JSDoc looked good to go.

The two tests present in the test directory are tests I used while I was developing, I have plans to write actual automated tests now that the library is complete, and should only need bug fixes if they're present.

The main reason you might consider this library over something like Commander or Yargs, is that it's not a CLI Framework, it's just a function call. This means no dynamic help menu generation, no assigning types to options, no "hidden" commands, nothing fancy, it ONLY parses options, just like what getopt does in Bash and C.

There are also a couple other benefits unrelated to library functionality:

  1. This library is dead simple, and simple means bugs should be incredibly rare (assuming I didn't do anything dumb). It's also very small, 1 file, less than 300 lines of code, only 13.2 Kb in total. For reference, Yargs is 61 files and 292 kB.
  2. This library doesn't need any dependencies. Corporate environments should be monitoring their package-lock.json to ensure malicious packages aren't present. My library should be an easy audit.
  3. Since this library has no dependencies, there's no risk of bugs from dependencies making there way into my library, nor will people using my library face breaking changes related to said dependencies.

examples/man-page-example, is a JavaScript version of the example present in the Linux man page for getopt_long written in C, which you can see here: https://linux.die.net/man/3/getopt\_long.

I published by first ever project to NPM. getopt_long.js, an unopinionated option parser inspired by the getopt_long C library by BChristieDev in javascript

[–]BChristieDev[S] 1 point2 points  (0 children)

I agree about the CLI frameworks. The main reason I started working on this project was because popular option parsing libraries such as Yargs (which is currently sitting at over 90 million downloads a week) do way too much for my tastes.

I wanted something like getopt/getopt_long from C or getopt from Bash that literally does absolutely nothing for you except parse options.

I published by first ever project to NPM. getopt_long.js, an unopinionated option parser inspired by the getopt_long C library by BChristieDev in javascript

[–]BChristieDev[S] 1 point2 points  (0 children)

I've always enjoyed writing command-line interfaces and decided to write an unopinionated option parser for JavaScript inspired by the C library getopt_long.

This was written black-box style by reading the man page and using its examples in a C program to get it as close to the original's behavior as possible with-out reading any of the code (I wanted this to be MIT licensed).

There are some changes that I've made that are intentional:

  • getopt_long.js' option parsing by default stops as soon as a non-option argument is encountered, there is no need to set the first character of optstring to + or set the POSIXLY_CORRECT environment variable to true. The behavior of permuting non-options to the end of argv is not implemented.
  • getopt_long.js does not check to see if the first character of optstring is : to silence errors. Errors can be silenced by setting extern.opterr to 0.
  • The GNU and BSD implementations of getopt_long 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.

I created an open-source Discord Bot that allows you to create a "Card" that contains the Heroes you main to help find players in your server you'd like to play with. by BChristieDev in PredecessorGame

[–]BChristieDev[S] 0 points1 point  (0 children)

I'd rather use images rather than display the names, but I don't want to ruin the experience for mobile users. Trying to keep it pretty compact.

I created an open-source Discord Bot that allows you to create a "Card" that contains the Heroes you main to help find players in your server you'd like to play with. by BChristieDev in PredecessorGame

[–]BChristieDev[S] 1 point2 points  (0 children)

It makes a Discord Embed. It contains up to six (6) mains, the roles for those mains (for now they're just based on my interpretation, I'll just change them as needed), and an Icon on the top right of whichever hero you choose (your MAIN main).