options-common.js
This file
Path
examples/options-common.js
25 lines · 751 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
1234567891011121314151617181920212223242526#!/usr/bin/env node
// This is used as an example in the README for:// Common option types, boolean and value
import { Command } from 'commander';const program = new Command();
program .option('-d, --debug', 'output extra debugging') .option('-s, --small', 'small pizza size') .option('-p, --pizza-type <type>', 'flavour of pizza');
program.parse(process.argv);
const options = program.opts();if (options.debug) console.log(options);console.log('pizza details:');if (options.small) console.log('- small pizza size');if (options.pizzaType) console.log(`- ${options.pizzaType}`);
// Try the following:// node options-common.js -p// node options-common.js -d -s -p vegetarian// node options-common.js --pizza-type=cheese