options-boolean-or-value.js
This file
Path
examples/options-boolean-or-value.js
23 lines · 782 bytes · JavaScript
Last changed by
Use standard import in examples (#2168)John Geebefore adoption41b12cf
History of this fileTake 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 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');Update dependencies (#1524)John Geebefore adoption0b0fbbe
lines 8–23why, one step back8const program = new commander.Command();910program11 .option('-c, --cheese [type]', 'Add cheese with optional type');1213program.parse(process.argv);1415const options = program.opts();16if (options.cheese === undefined) console.log('no cheese');17else if (options.cheese === true) console.log('add cheese');18else console.log(`add cheese type ${options.cheese}`);1920// Try the following:21// node options-boolean-or-value22// node options-boolean-or-value --cheese23// node options-boolean-or-value --cheese mozzarella