Skip to content
Myr

options-extra.js

This file

Path

examples/options-extra.js

51 lines · 1.4 KiB · JavaScript

Last changed by

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

History of this file

Take it

The walk stopped after 200 commits: lines older than 3103c6b point at it.

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 1–6why, one step back
1#!/usr/bin/env node
23// 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().6

Use standard import in examples (#2168)John Geebefore adoption41b12cf

line 7why, one step back
7const { Command, Option } = require('commander');

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 8–11why, one step back
8const program = new Command();
910program11 .addOption(new Option('-s, --secret').hideHelp())

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 12–24why, one step back
12 .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 more tests for implies (#1730)John Geebefore adoption3103c6b

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

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 26–38why, one step back
26 .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 more tests for implies (#1730)John Geebefore adoption3103c6b

lines 39–51why, one step back
39
40program.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