options-common.js
This file
Path
examples/options-common.js
25 lines · 751 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
The walk stopped after 200 commits: lines older than 471ec40 point at it.
Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 1–5why, one step back1#!/usr/bin/env node23// This is used as an example in the README for:4// Common option types, boolean and value5Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 6–7why, one step back6import { Command } from 'commander';7const program = new Command();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 8–25why, one step back89program10 .option('-d, --debug', 'output extra debugging')11 .option('-s, --small', 'small pizza size')12 .option('-p, --pizza-type <type>', 'flavour of pizza');1314program.parse(process.argv);1516const options = program.opts();17if (options.debug) console.log(options);18console.log('pizza details:');19if (options.small) console.log('- small pizza size');20if (options.pizzaType) console.log(`- ${options.pizzaType}`);2122// Try the following:23// node options-common.js -p24// node options-common.js -d -s -p vegetarian25// node options-common.js --pizza-type=cheese