options-env.js
This file
Path
examples/options-env.js
39 lines · 1.0 KiB · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than 3103c6b point at it.
Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 1why, one step back1#!/usr/bin/env nodeUse standard import in examples (#2168)John Geebefore adoption41b12cf
line 2why, one step back2const { Command, Option } = require('commander');Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 3–4why, one step back3const program = new Command();4Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 5–8why, one step back5program.addOption(6 new Option('-p, --port <number>', 'specify port number')7 .default(80)8 .env('PORT'),Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 9why, one step back9);Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 10–11why, one step back10program.addOption(11 new Option('-c, --colour', 'turn on colour output').env('COLOUR'),Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 12why, one step back12);Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 13–14why, one step back13program.addOption(14 new Option('-C, --no-colour', 'turn off colour output').env('NO_COLOUR'),Add more tests for implies (#1730)John Geebefore adoption3103c6b
line 15why, one step back15);Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 16–19why, one step back16program.addOption(17 new Option('-s, --size <type>', 'specify size of drink')18 .choices(['small', 'medium', 'large'])19 .env('SIZE'),Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 20–39why, one step back20);2122program.parse();23console.log(program.opts());2425// Try the following:26// node options-env.js --help27//28// node options-env.js29// PORT=9001 node options-env.js30// PORT=9001 node options-env.js --port 12331//32// COLOUR= node options-env.js33// COLOUR= node options-env.js --no-colour34// NO_COLOUR= node options-env.js35// NO_COLOUR= node options-env.js --colour36//37// SIZE=small node options-env.js38// SIZE=enormous node options-env.js39// SIZE=enormous node options-env.js --size=large