Skip to content
Myr

options-negatable.js

This file

Path

examples/options-negatable.js

26 lines · 941 bytes · JavaScript

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 0b0fbbe point at it.

Update dependencies (#1524)John Geebefore adoption0b0fbbe

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');

Update dependencies (#1524)John Geebefore adoption0b0fbbe

lines 8–26why, 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';19const cheeseStr = (options.cheese === false) ? 'no cheese' : `${options.cheese} cheese`;20console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`);2122// Try the following:23// node options-negatable.js24// node options-negatable.js --sauce25// node options-negatable.js --cheese=blue26// node options-negatable.js --no-sauce --no-cheese