options-implies.js
This file
Path
examples/options-implies.js
21 lines · 951 bytes · JavaScript
Last changed by
Assume a string parameter to implies is name of boolean option. (#1854)John Geebefore adoptionf4c7349
History of this fileTake it
Add Option.implies() (#1724)John Geebefore adoptiond660967
lines 1–21why, one step back1#!/usr/bin/env node2// const { Command, Option } = require('commander'); // (normal include)3const { Command, Option } = require('../'); // include commander in git clone of commander repo4const program = new Command();56program7 .addOption(new Option('--quiet').implies({ logLevel: 'off' }))8 .addOption(new Option('--log-level <level>').choices(['info', 'warning', 'error', 'off']).default('info'))9 .addOption(new Option('-c, --cheese <type>', 'Add the specified type of cheese').implies({ dairy: true }))10 .addOption(new Option('--no-cheese', 'You do not want any cheese').implies({ dairy: false }))11 .addOption(new Option('--dairy', 'May contain dairy'));1213program.parse();14console.log(program.opts());1516// Try the following:17// node options-implies.js18// node options-implies.js --quiet19// node options-implies.js --log-level=warning --quiet20// node options-implies.js --cheese=cheddar21// node options-implies.js --no-cheese