Skip to content
Myr

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 file

Take it

The walk stopped after 200 commits: lines older than 2aad525 point at it.

Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b

lines 1–2why, one step back
1#!/usr/bin/env node
2

Update dependencies (#1214)John Geebefore adoption2aad525

lines 3–8why, one step back
3// 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 back
9// .addCommand() adds a prepared command with an action handler.

Update dependencies (#1214)John Geebefore adoption2aad525

lines 10–18why, one step back
10
11// Add nested commands using `.command()`.12const brew = program.command('brew');13brew14 .command('tea')15 .action(() => {16 console.log('brew tea');17 });18brew

Merge pull request #1221 from shadowspawn/feature/nested-typosJohn Geebefore adoptionebc8b41

line 19why, one step back
19 .command('coffee')

Update dependencies (#1214)John Geebefore adoption2aad525

line 20why, one step back
20 .action(() => {

Merge pull request #1221 from shadowspawn/feature/nested-typosJohn Geebefore adoptionebc8b41

line 21why, one step back
21 console.log('brew coffee');

Update dependencies (#1214)John Geebefore adoption2aad525

lines 22–42why, one step back
22 });
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 back
43
44// Try the following:45// node nestedCommands.js brew tea46// node nestedCommands.js heat jug