argscan

1.0.0 • Public • Published

argscan

This is a very simple CLI argument parser optimized for Daplie style.

The main export is a scan function that expects a process.argv style array and returns you processed information such as the command, flags, and positional args.

Install

$ npm install --save argscan

Usage

// Pass the argv to the scan function to get parsed parts
var { command, flags, args } = require('argscan')(process.argv)
 
// Do logic using command string, flags map, and args list
switch (command) {
  case 'greet':
    if (flags.loudly) { console.log('HELLO ') }
    else { console.log ('hi') }
    break
  ...
}

Style

Daplie style arg parsing means a few assumptions.

Command

First you're expected to have several commands with optional : namespacing. For example yourprogram action:subaction where action:subaction is the command.

Also both long and short flags are supported. Long flags are expected to always look like --someFlag or --key=value. Short flags are single-character flags. You can have as many as you want on a single position. For example -tim is the same as -t -i -m. Both will generate a flags map of { t: true, i: true, m: true }.

Package Sidebar

Install

npm i argscan

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • creationix