options-env.js
This file
Path
examples/options-env.js
37 lines · 1.0 KiB · JavaScript
Last changed by
Use standard import in examples (#2168)John Geebefore adoption41b12cf
History of this fileTake it
Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
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 .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
lines 3–23why, one step back3const program = new Command();45program.addOption(new Option('-p, --port <number>', 'specify port number')6 .default(80)7 .env('PORT')8);9program.addOption(new Option('-c, --colour', 'turn on colour output')10 .env('COLOUR')11);12program.addOption(new Option('-C, --no-colour', 'turn off colour output')13 .env('NO_COLOUR')14);15program.addOption(new Option('-s, --size <type>', 'specify size of drink')16 .choices(['small', 'medium', 'large'])17 .env('SIZE')18);1920program.parse();21console.log(program.opts());2223// Try the following:Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
line 24why, one step back24// node options-env.js --helpAdd .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
line 25why, one step back25//Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 26–28why, one step back26// node options-env.js27// PORT=9001 node options-env.js28// PORT=9001 node options-env.js --port 123Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
line 29why, one step back29//Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 30–33why, one step back30// COLOUR= node options-env.js31// COLOUR= node options-env.js --no-colour32// NO_COLOUR= node options-env.js33// NO_COLOUR= node options-env.js --colourAdd .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
line 34why, one step back34//Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 35–37why, one step back35// SIZE=small node options-env.js36// SIZE=enormous node options-env.js37// SIZE=enormous node options-env.js --size=large