New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

bebopt

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bebopt

a more powerful, option parser for node.js

latest
Source
npmnpm
Version
0.2.4
Version published
Maintainers
1
Created
Source

Bebopt Build Status

a more powerful option parser for node.js

NOTE

If you're looking for documentation, please refer to the wiki.

Why another option parser?

Because I'm tired of using option parsers that don't do their jobs very well. Nearly every parser I've used has required either a workaround to actually make it work, or boilerplate code that's off-putting (at least, for some developers). In short: untraditional implementations and poor abstractions.

Some examples

Take optimist and yargs, for example: both of them are great parsers in their own right, but they provide no method or abstraction for handling arguments in the order in which they appear on the command-line.

Instead, the way I've seen most people use both of these excellent parsers inherently makes their programs handle args in the order in which they are handled:

#!/usr/bin/env node
// ex.js
// an example of optimist in action
var args = require('optimist')
    .usage('Do stuff')
    .describe('h', 'print this message and exit')
    .describe('v', 'print program version and exit')
    .argv;

if (args.v)
  console.log('1.0');
  process.exit(0);
if (args.h)
  args.showHelp();
  process.exit(0);

Because -v is handled before -h; so even if you run node ex.js -h -v, the version string will always get printed instead of the expected usage information.

In optimist, the problem can sort of be resolved by looping over the resulting args object using Object.key like so:

#!/usr/bin/env node
// ex.js
// an example of optimist in action
var args = require('optimist')
    .usage('Do stuff')
    .describe('h', 'print this message and exit')
    .describe('v', 'print program version and exit')
    .argv;

// doesn't capture commands
// can also be done in a really ugly way like so:
// Object.keys(args).slice(Object.keys(args).indexOf('$0') + 1)
Object.keys(args).slice(2).forEach(function(key) {
  /* process args using a switch */
});

I say sort of because the above solution doesn't capture commands, is ugly, and doesn't work with yargs!!

Keywords

getopt

FAQs

Package last updated on 10 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts