options-boolean-or-value.js
This file
Path
examples/options-boolean-or-value.js
22 lines · 779 bytes · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake it
The walk stopped after 200 commits: lines older than 3103c6b point at it.
Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 1–6why, one step back1#!/usr/bin/env node23// This is used as an example in the README for:4// Other option types, flag|value5// You can specify an option which functions as a flag but may also take a value (declared using square brackets).6Use standard import in examples (#2168)John Geebefore adoption41b12cf
line 7why, one step back7const commander = require('commander');Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 8–9why, one step back8const program = new commander.Command();9Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 10why, one step back10program.option('-c, --cheese [type]', 'Add cheese with optional type');Add more tests for implies (#1730)John Geebefore adoption3103c6b
lines 11–22why, one step back1112program.parse(process.argv);1314const options = program.opts();15if (options.cheese === undefined) console.log('no cheese');16else if (options.cheese === true) console.log('add cheese');17else console.log(`add cheese type ${options.cheese}`);1819// Try the following:20// node options-boolean-or-value21// node options-boolean-or-value --cheese22// node options-boolean-or-value --cheese mozzarella