Skip to content
Myr

options-boolean-or-value.js

This file

Path

examples/options-boolean-or-value.js

22 lines · 766 bytes · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

The walk stopped after 200 commits: lines older than 471ec40 point at it.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1–6why, one step back
1#!/usr/bin/env node
23// This is used as an example in the README for:4// Other option types, flag|value5// You can specify an option which functions as a flag but may also take a value (declared using square brackets).6

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

lines 7–8why, one step back
7import { Command } from 'commander';
8const program = new Command();

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

line 9why, one step back
9

Reformat code with Prettier (#2180)John Geebefore adoption1bdc749

line 10why, one step back
10program.option('-c, --cheese [type]', 'Add cheese with optional type');

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 11–22why, one step back
11
12program.parse(process.argv);1314const options = program.opts();15if (options.cheese === undefined) console.log('no cheese');16else if (options.cheese === true) console.log('add cheese');17else console.log(`add cheese type ${options.cheese}`);1819// Try the following:20// node options-boolean-or-value21// node options-boolean-or-value --cheese22// node options-boolean-or-value --cheese mozzarella