options-negatable.js
This file
Path
examples/options-negatable.js
27 lines · 944 bytes · JavaScript
Last changed by
Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a
History of this fileTake it
The walk stopped after 200 commits: lines older than d660967 point at it.
Add Option.implies() (#1724)John Geebefore adoptiond660967
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.6Use standard import in examples (#2168)John Geebefore adoption41b12cf
line 7why, one step back7const commander = require('commander');Add Option.implies() (#1724)John Geebefore adoptiond660967
lines 8–18why, one step back8const program = new commander.Command();910program11 .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 Option.implies() (#1724)John Geebefore adoptiond660967
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 Option.implies() (#1724)John Geebefore adoptiond660967
lines 26–27why, one step back26// node options-negatable.js --cheese=blue27// node options-negatable.js --no-sauce --no-cheese