1.0.1 • Published 8 years ago

sheepskin v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 years ago

sheepskin

npm license status dependencies

A light weight command line interface tester.

$ npm install --global sheepskin

Usage

Add documentation to your CLI source code!

Note: I'm using commander.js here just for clarity.

const program = require('commander');
const getStdin = require('get-stdin');

/**
 * @verb add
 * @pipe starting value
 *
 * @input
 *   add --value 2 --value 3
 * @output
 *   5
 *
 * @input
 *  add --value 4 --value 6 --value 2 | add --value 12 --value 18
 * @output
 *  life
 */
program
  .command('add')
  .description('add values together')
  .option('-v, --value [v]', 'A repeatable value', (val, values) => {
    values.push(parseFloat(val) || 0);
    return values;
  }, [])
  .action((options) => { program.value = options.value; });

program.parse(process.argv);

getStdin()
  .then(input => {
    input = parseFloat(input) || 0;

    var result = program.value.reduce((acc, val) => acc + val, input);
    console.log(result !== 42 ? result : 'life');
});