Skip to content
Myr

options-negatable.js

This file

Path

examples/options-negatable.js

27 lines · 941 bytes · JavaScript

Last changed by

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

History of this file

Take 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 back
1#!/usr/bin/env node
23// 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.6

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

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

Add Option.implies() (#1724)John Geebefore adoptiond660967

lines 8–18why, one step back
8const 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 back
19const cheeseStr =
20 options.cheese === false ? 'no cheese' : `${options.cheese} cheese`;

Add Option.implies() (#1724)John Geebefore adoptiond660967

lines 21–27why, one step back
21console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);
2223// Try the following:24// node options-negatable.js25// node options-negatable.js --sauce26// node options-negatable.js --cheese=blue27// node options-negatable.js --no-sauce --no-cheese