Skip to content
Myr

defaultCommand.js

This file

Path

examples/defaultCommand.js

36 lines · 952 bytes · 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 30ae4ac 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

Parse argument conventions (#1172)John Geebefore adoption30ae4ac

lines 3–26why, 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// Example program using the command configuration option isDefault to specify the default command.89program10 .command('build')11 .description('build web site for deployment')12 .action(() => {13 console.log('build');14 });1516program17 .command('deploy')18 .description('deploy web site to production')19 .action(() => {20 console.log('deploy');21 });2223program24 .command('serve', { isDefault: true })25 .description('launch web server')26 .option('-p,--port <port_number>', 'web port')

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

lines 27–28why, one step back
27 .action((options) => {
28 console.log(`server on port ${options.port}`);

Parse argument conventions (#1172)John Geebefore adoption30ae4ac

lines 29–31why, one step back
29 });
3031program.parse(process.argv);

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

lines 32–36why, one step back
32
33// Try the following:34// node defaultCommand.js build35// node defaultCommand.js serve -p 808036// node defaultCommand.js -p 443