Skip to content
Myr

thank.js

This file

Path

examples/thank.js

26 lines · 831 bytes · JavaScript

Last changed by

Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36

History of this file

Take it

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

lines 1–9why, one step back
1#!/usr/bin/env node
23// This example is used as an example in the README for the action handler.45// const { Command } = require('commander'); // (normal include)6const { Command } = require('../'); // include commander in git clone of commander repo7const program = new Command();89program

More consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9

line 10why, one step back
10 .argument('<name>')

Change to safe storage of options by default, and change action parameters (#1409)John Geebefore adoptionf76bc71

lines 11–23why, one step back
11 .option('-t, --title <honorific>', 'title to use before name')
12 .option('-d, --debug', 'display some debugging')13 .action((name, options, command) => {14 if (options.debug) {15 console.error('Called %s with options %o', command.name(), options);16 }17 const title = options.title ? `${options.title} ` : '';18 console.log(`Thank-you ${title}${name}`);19 });2021program.parse();2223// Try the following:

Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36

lines 24–26why, one step back
24// node thank.js John
25// node thank.js Doe --title Mr26// node thank.js --debug Doe --title Mr