options-required.js
This file
Path
examples/options-required.js
19 lines · 570 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
1234567891011121314151617181920#!/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.
import { Command } from 'commander';const program = new 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