npm.io
1.11.0 • Published 4 years ago

chickpea

Licence
ISC
Version
1.11.0
Deps
2
Size
36 kB
Vulns
0
Weekly
0

chickpea

A little bean for parsing command line arguments without any surprises, at all.

Install


npm i chickpea

Example


#!/usr/bin/env node

const chickpea = require('chickpea');
const program = require('./index.js');

const configuration = { input: 'Input PNG' };
const options = chickpea(configuration);

program(options)

Usage


#!/usr/bin/env node

const chickpea = require('chickpea');

const pizzaOrder = chickpea({

  pepper_flag: 'Add peppers.',
  pineapple_flag: 'Add pineapple.',
  bbqSauce_flag: 'Add bbq sauce.',
  cheese: 'Add the specified type of cheese: --cheese gorgonzola',
  firstName: 'First name.',
  lastName: 'Last name.',

});

console.log('Cheese Type:', pizzaOrder.cheese);
console.log('BBQ Sauce:', pizzaOrder.bbqSauce?'yes':'no');
Execute

$ ./example.js --cheese "Super Stinky" --bbq-sauce
Result

Cheese Type: Super Stinky
BBQ Sauce: yes
Extras

When executing with -h flag you get the following

$ ./example.js -h


  Usage: example [options]

  Options:

    -V, --version           output the version number
    -p,--pepper             Add peppers.
    -i,--pineapple          Add pineapple.
    -b,--bbq-sauce          Add bbq sauce.
    -c,--cheese [text]      Add the specified type of cheese: --cheese gorgonzola
    -f,--first-name [text]  First name.
    -l,--last-name [text]   Last name.
    -h, --help              output usage information