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 fileTake it
The walk stopped after 200 commits: lines older than bdad7dc point at it.
Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b
lines 1–2why, one step back1#!/usr/bin/env node2update Readme_zh-CN.md for v5.0oGsLPbefore adoptionbdad7dc
lines 3–26why, 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// 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 back27 .action((options) => {28 console.log(`server on port ${options.port}`);update Readme_zh-CN.md for v5.0oGsLPbefore adoptionbdad7dc
lines 29–31why, one step back29 });3031program.parse(process.argv);Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
lines 32–36why, one step back3233// Try the following:34// node defaultCommand.js build35// node defaultCommand.js serve -p 808036// node defaultCommand.js -p 443