Skip to content
Myr

options-extra.js

This file

Path

examples/options-extra.js

31 lines · 1.4 KiB · JavaScript

Last changed by

Add Option.implies() (#1724)John Geebefore adoptiond660967

History of this file

Take it

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

lines 1–3why, one step back
1#!/usr/bin/env node
23// This is used as an example in the README for extra option features.

Add extended conflicts example (#1700)John Geebefore adoption1d27078

lines 4–5why, one step back
4// See also options-env.js for more extensive env examples,
5// and options-conflicts.js for more details about .conflicts().

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

line 6why, one step back
6

Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75

lines 7–9why, one step back
7// const { Command, Option } = require('commander'); // (normal include)
8const { Command, Option } = require('../'); // include commander in git clone of commander repo9const program = new Command();

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

lines 10–11why, one step back
10
11program

Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75

lines 12–14why, one step back
12 .addOption(new Option('-s, --secret').hideHelp())
13 .addOption(new Option('-t, --timeout <delay>', 'timeout in seconds').default(60, 'one minute'))14 .addOption(new Option('-d, --drink <size>', 'drink cup size').choices(['small', 'medium', 'large']))

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

line 15why, one step back
15 .addOption(new Option('-p, --port <number>', 'port number').env('PORT'))

feat(option): allow to set options as conflicting (#1678)Erez Rokahbefore adoptionfc4fd41

line 16why, one step back
16 .addOption(new Option('--donate [amount]', 'optional donation in dollars').preset('20').argParser(parseFloat))

Add Option.implies() (#1724)John Geebefore adoptiond660967

lines 17–18why, one step back
17 .addOption(new Option('--disable-server', 'disables the server').conflicts('port'))
18 .addOption(new Option('--free-drink', 'small drink included free ').implies({ drink: 'small' }));

Enhance Option class to allow hiding help, specifying choices, and change how default value displayed in help (#1331)John Geebefore adoptiona05a8bc

lines 19–24why, one step back
19
20program.parse();2122console.log('Options: ', program.opts());2324// Try the following:

Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36

lines 25–26why, one step back
25// node options-extra.js --help
26// node options-extra.js --drink huge

Add Option.implies() (#1724)John Geebefore adoptiond660967

line 27why, one step back
27// node options-extra.js --free-drink

Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36

line 28why, one step back
28// PORT=80 node options-extra.js

Merge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c

lines 29–30why, one step back
29// node options-extra.js --donate
30// node options-extra.js --donate 30.50

feat(option): allow to set options as conflicting (#1678)Erez Rokahbefore adoptionfc4fd41

line 31why, one step back
31// node options-extra.js --disable-server --port 8000