Skip to content
Myr

arguments-extra.js

This file

Path

examples/arguments-extra.js

22 lines · 716 bytes · JavaScript

Last changed by

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

History of this file

Take it

Choices for arguments (#1525)John Geebefore adoption708527e

lines 1–4why, one step back
1#!/usr/bin/env node
23// This is used as an example in the README for extra argument features.4

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

line 5why, one step back
5const commander = require('commander');

Choices for arguments (#1525)John Geebefore adoption708527e

lines 6–18why, one step back
6const program = new commander.Command();
78program9 .addArgument(new commander.Argument('<drink-size>', 'drink cup size').choices(['small', 'medium', 'large']))10 .addArgument(new commander.Argument('[timeout]', 'timeout in seconds').default(60, 'one minute'))11 .action((drinkSize, timeout) => {12 console.log(`Drink size: ${drinkSize}`);13 console.log(`Timeout (s): ${timeout}`);14 });1516program.parse();1718// Try the following:

Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36

lines 19–22why, one step back
19// node arguments-extra.js --help
20// node arguments-extra.js huge21// node arguments-extra.js small22// node arguments-extra.js medium 30