options-extra.js
This file
Path
examples/options-extra.js
51 lines · 1.4 KiB · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 1–6why, one step back1#!/usr/bin/env node23// This is used as an example in the README for extra option features.4// See also options-env.js for more extensive env examples,5// and options-conflicts.js for more details about .conflicts().6Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 7why, one step back7import { Command, Option } from 'commander';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 8–11why, one step back8const program = new Command();910program11 .addOption(new Option('-s, --secret').hideHelp())Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 12–24why, one step back12 .addOption(13 new Option('-t, --timeout <delay>', 'timeout in seconds').default(14 60,15 'one minute',16 ),17 )18 .addOption(19 new Option('-d, --drink <size>', 'drink cup size').choices([20 'small',21 'medium',22 'large',23 ]),24 )Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
line 25why, one step back25 .addOption(new Option('-p, --port <number>', 'port number').env('PORT'))Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 26–38why, one step back26 .addOption(27 new Option('--donate [amount]', 'optional donation in dollars')28 .preset('20')29 .argParser(parseFloat),30 )31 .addOption(32 new Option('--disable-server', 'disables the server').conflicts('port'),33 )34 .addOption(35 new Option('--free-drink', 'small drink included free ').implies({36 drink: 'small',37 }),38 );Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 39–51why, one step back3940program.parse();4142console.log('Options: ', program.opts());4344// Try the following:45// node options-extra.js --help46// node options-extra.js --drink huge47// node options-extra.js --free-drink48// PORT=80 node options-extra.js49// node options-extra.js --donate50// node options-extra.js --donate 30.5051// node options-extra.js --disable-server --port 8000