Skip to content
Myr

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 file

Take 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 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

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 7–8why, one step back
7import { Command } from 'commander';
8const program = new Command();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 9–18why, one step back
9
10program11 .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 copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Make order not matter for adding combo positive/negative options (#2405)John Geebefore adoption63eed4a

line 25why, one step back
25// node options-negatable.js --no-sauce

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 26–27why, one step back
26// node options-negatable.js --cheese=blue
27// node options-negatable.js --no-sauce --no-cheese