+ All Categories
Home > Technology > Peggy optimist

Peggy optimist

Date post: 20-Feb-2017
Category:
Upload: learningtech
View: 275 times
Download: 0 times
Share this document with a friend
17
Optimist PEGGY 2015-07-31
Transcript

OptimistPEGGY2015-07-31

INPUT node optimist.js -r=55 node optimist.js -r 55

Options Are Just A Hash

node optimist.js --rif=55 --xup=9.52 Buy more riffiwobbles

node optimist.js --rif 12 --xup 8.1 Sell the xupptumblers

var argv = require('optimist').argv; if (argv.rif - 5 * argv.xup > 7.138) {    console.log('Buy more riffiwobbles');}else {    console.log('Sell the xupptumblers');}

Non-hypenated Options

node optimist.js -x 6.82 -y 3.35 moo (6.82,3.35) [ 'moo' ]

node optimist.js foo -x 0.54 bar -y 1.12 baz (0.54,1.12) [ 'foo', 'bar', 'baz' ]

var argv = require('optimist').argv;console.log('(%d,%d)', argv.x, argv.y);console.log(argv._);

Get All Descriptive About It...

node optimist.js –a

node optimist.js -a 123 test

var argv = require('optimist')    .argv;console. log(argv);{ _: [],

a: true, '$0': 'node D:\\optimist.js' }

{ _: [‘test’], a: 123, '$0': 'node D:\\optimist.js' }

.boolean(key)

node optimist.js -v foo bar baz true

var argv = require('optimist')    .boolean('v')    .argv;console.log(argv.v);

.default(key, value)

node optimist.js -x 515

var argv = require('optimist')    .default('x', 10)    .default('y', 10)    .argv;console.log(argv.x + argv.y);

var argv = require('optimist')    .default({ x : 10, y : 10 })    .argv;console.log(argv.x + argv.y);

.alias(key, alias)

node optimist.js -f node optimist.js --file

var argv = require('optimist')    .alias('f', 'file');

.usage(message) & .demand(key)

node optimist.js -x 55 -y 11 5

node optimist.js -x 4.91 -z 2.51 Usage: node ./optimist.js -x [num] -y [num] Options:

-x [required] -y [required]

Missing required arguments: y

var argv = require('optimist')    .usage('Usage: $0 -x [num] -y [num]')    .demand(['x','y'])    .argv; console.log(argv.x / argv.y);

.describe(key, desc)

node optimist.jsCount the lines in a file.Usage: node D:\optimist.jsOptions: -f, --file Load a file [required]Missing required arguments: f

var argv = require('optimist')    .usage('Count the lines in a file.\nUsage: $0')    .demand('f')    .alias('f', 'file')    .describe('f', 'Load a file')    .argv;

.help()

Return the generated usage string. node optimist.js -f

'Count the lines in a file.\nUsage: node D:\\optimist.js\n\nOptions:\n -f, --file Load a file [required]\n'

var optimist = require('optimist')    .usage('Count the lines in a file.\nUsage: $0')    .demand('f')    .alias('f', 'file')    .describe('f', 'Load a file');console.log(optimist.help());

.showHelp()

Print the usage data using fn for printing. node optimist.js -f

Count the lines in a file.Usage: node D:\optimist.js

Options: -f, --file Load a file [required]

var optimist = require('optimist')    .usage('Count the lines in a file.\nUsage: $0')    .demand('f')    .alias('f', 'file')    .describe('f', 'Load a file');console.log(optimist.showHelp());

.showHelp()

node optimist.js -hCount the lines in a file.Usage: node D:\optimist.js

Options: -f, --file Load a file -h, --help Display the usage

var optimist = require('optimist')    .usage('Count the lines in a file.\nUsage: $0')    .alias('f', 'file')    .alias('h', 'help')    .describe('f', 'Load a file') .describe('h', 'Display the usage') .argv;

if(argv.help){ optimist.showHelp(); process.exit(0);}

.options(key, opt)

var argv = require('optimist')    .options('f', {        alias : 'file',        default : '/etc/passwd',    })    .argv;

var argv = require('optimist')    .alias('f', 'file')    .default('f', '/etc/passwd')    .argv;

Duplicates

node optimist.js -x 5 -x 8 -x 0{ _: [], x: [ 5, 8, 0 ], '$0': 'node D:\\optimist.js' }

Dot Notation

node optimist.js --foo.bar.baz=33 --foo.quux=5{ _: [], foo: { bar: { baz: 33 }, quux: 5 }, '$0': 'node D:\\optimist.js' }

Negate Fields

If you want to explicity set a field to false instead of just leaving it undefined or to override a default you can do --no-key.

node optimist.js -a --no-b{ _: [], a: true, b: false, '$0': 'node D:\\optimist.js' }


Recommended