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 fileTake 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 back1#!/usr/bin/env node23// 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 back4// 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 back6Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
lines 7–9why, one step back7// 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 back1011programAdd .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
lines 12–14why, one step back12 .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 back15 .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 back16 .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 back17 .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 back1920program.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 back25// node options-extra.js --help26// node options-extra.js --drink hugeAdd Option.implies() (#1724)John Geebefore adoptiond660967
line 27why, one step back27// node options-extra.js --free-drinkMake examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
line 28why, one step back28// PORT=80 node options-extra.jsMerge pull request #1683 from tj/release/9.xJohn Geebefore adoption02a124c
lines 29–30why, one step back29// node options-extra.js --donate30// node options-extra.js --donate 30.50feat(option): allow to set options as conflicting (#1678)Erez Rokahbefore adoptionfc4fd41
line 31why, one step back31// node options-extra.js --disable-server --port 8000