options-implies.js
This file
Path
examples/options-implies.js
22 lines · 1.0 KiB · JavaScript
Last changed by
Add Option.implies() (#1724)John Geebefore adoptiond660967
History of this fileTake it
Add Option.implies() (#1724)John Geebefore adoptiond660967
lines 1–22why, 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();56// You can use .conflicts() with a single string, which is the camel-case name of the conflicting option.7program8 .addOption(new Option('--quiet').implies({ logLevel: 'off' }))9 .addOption(new Option('--log-level <level>').choices(['info', 'warning', 'error', 'off']).default('info'))10 .addOption(new Option('-c, --cheese <type>', 'Add the specified type of cheese').implies({ dairy: true }))11 .addOption(new Option('--no-cheese', 'You do not want any cheese').implies({ dairy: false }))12 .addOption(new Option('--dairy', 'May contain dairy'));1314program.parse();15console.log(program.opts());1617// Try the following:18// node options-implies.js19// node options-implies.js --quiet20// node options-implies.js --log-level=warning --quiet21// node options-implies.js --cheese=cheddar22// node options-implies.js --no-cheese