Skip to content
Myr

options-env.js

This file

Path

examples/options-env.js

39 lines · 1.0 KiB · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

The walk stopped after 200 commits: lines older than 471ec40 point at it.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 1why, one step back
1#!/usr/bin/env node

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 2why, one step back
2import { Command, Option } from 'commander';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 3–4why, one step back
3const program = new Command();
4

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 5–8why, one step back
5program.addOption(
6 new Option('-p, --port <number>', 'specify port number')7 .default(80)8 .env('PORT'),

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 9why, one step back
9);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 10–11why, one step back
10program.addOption(
11 new Option('-c, --colour', 'turn on colour output').env('COLOUR'),

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 12why, one step back
12);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 13–14why, one step back
13program.addOption(
14 new Option('-C, --no-colour', 'turn off colour output').env('NO_COLOUR'),

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 15why, one step back
15);

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

lines 16–19why, one step back
16program.addOption(
17 new Option('-s, --size <type>', 'specify size of drink')18 .choices(['small', 'medium', 'large'])19 .env('SIZE'),

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 20–39why, one step back
20);
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