nestedCommands.js
This file
Path
examples/nestedCommands.js
46 lines · 1.1 KiB · JavaScript
Last changed by
Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
History of this fileTake it
The walk stopped after 200 commits: lines older than fbdd132 point at it.
Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 1–2why, one step back1#!/usr/bin/env node2Replace git-style wording from README (#1171)John Geebefore adoptionfbdd132
lines 3–8why, one step back3// const commander = require('commander'); // (normal include)4const commander = require('../'); // include commander in git clone of commander repo5const program = new commander.Command();67// Commander supports nested subcommands.8// .command() can add a subcommand with an action handler or an executable.Merge pull request #1221 from shadowspawn/feature/nested-typosJohn Geebefore adoptionebc8b41
line 9why, one step back9// .addCommand() adds a prepared command with an action handler.Replace git-style wording from README (#1171)John Geebefore adoptionfbdd132
lines 10–18why, one step back1011// Add nested commands using `.command()`.12const brew = program.command('brew');13brew14 .command('tea')15 .action(() => {16 console.log('brew tea');17 });18brewMerge pull request #1221 from shadowspawn/feature/nested-typosJohn Geebefore adoptionebc8b41
line 19why, one step back19 .command('coffee')Replace git-style wording from README (#1171)John Geebefore adoptionfbdd132
line 20why, one step back20 .action(() => {Merge pull request #1221 from shadowspawn/feature/nested-typosJohn Geebefore adoptionebc8b41
line 21why, one step back21 console.log('brew coffee');Replace git-style wording from README (#1171)John Geebefore adoptionfbdd132
lines 22–42why, one step back22 });2324// Add nested commands using `.addCommand().25// The command could be created separately in another module.26function makeHeatCommand() {27 const heat = new commander.Command('heat');28 heat29 .command('jug')30 .action(() => {31 console.log('heat jug');32 });33 heat34 .command('pot')35 .action(() => {36 console.log('heat pot');37 });38 return heat;39}40program.addCommand(makeHeatCommand());4142program.parse(process.argv);Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 43–46why, one step back4344// Try the following:45// node nestedCommands.js brew tea46// node nestedCommands.js heat jug