Skip to content
Myr

options-negatable.js

This file

Path

examples/options-negatable.js

27 lines · 1.0 KiB · JavaScript

Last changed by

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

History of this file

Take it

The walk stopped after 200 commits: lines older than 2aad525 point at it.

Update dependencies (#1214)John Geebefore adoption2aad525

lines 1–13why, 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.67// const commander = require('commander'); // (normal include)8const commander = require('../'); // include commander in git clone of commander repo9const program = new commander.Command();1011program12 .option('--no-sauce', 'Remove sauce')13 .option('--cheese <flavour>', 'cheese flavour', 'mozzarella')

Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b

lines 14–15why, one step back
14 .option('--no-cheese', 'plain with no cheese');
15

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

line 16why, one step back
16program.parse();

Update dependencies (#1214)John Geebefore adoption2aad525

line 17why, one step back
17

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

lines 18–20why, one step back
18const options = program.opts();
19const sauceStr = options.sauce ? 'sauce' : 'no sauce';20const cheeseStr = (options.cheese === false) ? 'no cheese' : `${options.cheese} cheese`;

Update dependencies (#1214)John Geebefore adoption2aad525

line 21why, one step back
21console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

lines 22–27why, one step back
22
23// 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