options-required.js
This file
Path
examples/options-required.js
21 lines · 695 bytes · JavaScript
Last changed by
Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
History of this fileTake it
12345678910111213141516171819202122#!/usr/bin/env node
// This is used as an example in the README for:// Required option// You may specify a required (mandatory) option using `.requiredOption`.// The option must be specified on the command line, or by having a default value.
// const commander = require('commander'); // (normal include)const commander = require('../'); // include commander in git clone of commander repoconst program = new commander.Command();
program .requiredOption('-c, --cheese <type>', 'pizza must have cheese');
program.parse();
console.log(`Cheese type: ${program.opts().cheese}`);
// Try the following:// node options-required.js// node options-required.js --cheese blue