options-env.js
This file
Path
examples/options-env.js
38 lines · 1.1 KiB · JavaScript
Last changed by
Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
History of this fileTake it
Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
lines 1–24why, one step back1#!/usr/bin/env node2// const { Command, Option } = require('commander'); // (normal include)3const { Command, Option } = require('../'); // include commander in git clone of commander repo4const program = new Command();56program.addOption(new Option('-p, --port <number>', 'specify port number')7 .default(80)8 .env('PORT')9);10program.addOption(new Option('-c, --colour', 'turn on colour output')11 .env('COLOUR')12);13program.addOption(new Option('-C, --no-colour', 'turn off colour output')14 .env('NO_COLOUR')15);16program.addOption(new Option('-s, --size <type>', 'specify size of drink')17 .choices(['small', 'medium', 'large'])18 .env('SIZE')19);2021program.parse();22console.log(program.opts());2324// Try the following:Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
line 25why, one step back25// node options-env.js --helpAdd .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
line 26why, one step back26//Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 27–29why, one step back27// node options-env.js28// PORT=9001 node options-env.js29// PORT=9001 node options-env.js --port 123Add .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
line 30why, one step back30//Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 31–34why, one step back31// COLOUR= node options-env.js32// COLOUR= node options-env.js --no-colour33// NO_COLOUR= node options-env.js34// NO_COLOUR= node options-env.js --colourAdd .env method to Option for consulting environment variable for option value (#1587)John Geebefore adoption8571a75
line 35why, one step back35//Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 36–38why, one step back36// SIZE=small node options-env.js37// SIZE=enormous node options-env.js38// SIZE=enormous node options-env.js --size=large