Add README reference and example output to new examples
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by John Gee · parent 57a3375 · Browse files · 5 files·+84 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+84 added−5 removed
- other:+84 added−5 removed
Provenance
- Commit
ccee61c- Tree
ad1a8a9- Author
John Gee <john@ruru.gen.nz>- Committer
John Gee <john@ruru.gen.nz>- Parent
57a3375
5 files changed+84 added−5 removed
modified:examples/options-common.js+22 added-1 removed
123345678910111213141516171819202122232425262728297 unmodified lines#!/usr/bin/env node
const program = require('commander');// This is used as an example in the README for:// Common option types, boolean and value// The two most used option types are a boolean flag, and an option which takes a value (declared using angle brackets).//// Example output pretending command called pizza-options (or try directly with `node options-common.js`)//// $ pizza-options -d// { debug: true, small: undefined, pizzaType: undefined }// pizza details:// $ pizza-options -p// error: option `-p, --pizza-type <type>' argument missing// $ pizza-options -ds -p vegetarian// { debug: true, small: true, pizzaType: 'vegetarian' }// pizza details:// - small pizza size// - vegetarian// $ pizza-options --pizza-type=cheese// pizza details:// - cheese
const commander = require('commander');const program = new commander.Command();
program .option('-d, --debug', 'output extra debugging') .option('-s, --small', 'small pizza size') .option('-p, --pizza-type <type>', 'flavour of pizza');7 unmodified linesmodified:examples/options-custom-processing.js+19 added-1 removed
1233456789101112131415161718192021222324252627 unmodified lines#!/usr/bin/env node
const program = require('commander');// This is used as an example in the README for:// Custom option processing// You may specify a function to do custom processing of option values. ...//// Example output pretending command called custom (or try directly with `node options-custom-processing.js`)//// $ custom -f 1e2// float: 100// $ custom --integer 2// integer: 2// $ custom -v -v -v// verbose: 3// $ custom -c a -c b -c c// [ 'a', 'b', 'c' ]// $ custom --list x,y,z// [ 'x', 'y', 'z' ]
const commander = require('commander');const program = new commander.Command();
function myParseInt(value, dummyPrevious) { // parseInt takes a string and a radix return parseInt(value, 10);}27 unmodified linesmodified:examples/options-defaults.js+13 added-1 removed
123345678910111213141516171819202 unmodified lines#!/usr/bin/env node
const program = require('commander');// This is used as an example in the README for:// Default option value// You can specify a default value for an option which takes a value.//// Example output pretending command called pizza-options (or try directly with `node options-defaults.js`)//// $ pizza-options// cheese: blue// $ pizza-options --cheese stilton// cheese: stilton
const commander = require('commander');const program = new commander.Command();
program .option('-c, --cheese <type>', 'Add the specified type of cheese', 'blue');
program.parse(process.argv);2 unmodified linesmodified:examples/options-flag-or-value.js+15 added-1 removed
1233456789101112131415161718192021224 unmodified lines#!/usr/bin/env node
const program = require('commander');// This is used as an example in the README for:// Other option types, flag|value// You can specify an option which functions as a flag but may also take a value (declared using square brackets).//// Example output pretending command called pizza-options (or try directly with `node options-flag-or-value.js`)//// $ pizza-options// no cheese// $ pizza-options --cheese// add cheese// $ pizza-options --cheese mozzarella// add cheese type mozzarella
const commander = require('commander');const program = new commander.Command();
program .option('-c, --cheese [type]', 'Add cheese with optional type');
program.parse(process.argv);4 unmodified linesmodified:examples/options-negatable.js+15 added-1 removed
1233456789101112131415161718192021222 unmodified lines#!/usr/bin/env node
const program = require('commander');// This is used as an example in the README for:// Other option types, negatable boolean// You can specify a boolean option long name with a leading `no-` to make it true by default and able to be negated.//// Example output pretending command called pizza-options (or try directly with `node options-negatable.js`)//// $ pizza-options// you ordered a pizza with sauce// $ pizza-options --sauce// error: unknown option `--sauce'// $ pizza-options --no-sauce// you ordered a pizza without sauce
const commander = require('commander');const program = new commander.Command();
program .option('-n, --no-sauce', 'Remove sauce') .parse(process.argv);
2 unmodified lines