options-negatable.js
This file
Path
examples/options-negatable.js
27 lines · 931 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–6why, one step back1#!/usr/bin/env node23// This is used as an example in the README for:4// Other option types, negatable boolean5// You can specify a boolean option long name with a leading `no-` to make it true by default and able to be negated.6Switching to esm-only (#2464)John Geebefore adoptionf4bd470
lines 7–8why, one step back7import { Command } from 'commander';8const program = new Command();Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 9–18why, one step back910program11 .option('--no-sauce', 'Remove sauce')12 .option('--cheese <flavour>', 'cheese flavour', 'mozzarella')13 .option('--no-cheese', 'plain with no cheese');1415program.parse();1617const options = program.opts();18const sauceStr = options.sauce ? 'sauce' : 'no sauce';Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
lines 19–20why, one step back19const cheeseStr =20 options.cheese === false ? 'no cheese' : `${options.cheese} cheese`;Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 21–24why, one step back21console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);2223// Try the following:24// node options-negatable.jsMake order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
line 25why, one step back25// node options-negatable.js --no-sauceAdd copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 26–27why, one step back26// node options-negatable.js --cheese=blue27// node options-negatable.js --no-sauce --no-cheese