Skip to content
Myr

defaultCommand.js

This file

Path

examples/defaultCommand.js

38 lines · 983 bytes · JavaScript

Last changed by

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

History of this file

Take 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 rework for nested commands (#1149)John Geebefore adoption1345f98

lines 3–33why, 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.8//9// $ node defaultCommand.js build10// build11// $ node defaultCommand.js serve -p 808012// server on port 808013// $ node defaultCommand.js -p 44314// server on port 4431516program17 .command('build')18 .description('build web site for deployment')19 .action(() => {20 console.log('build');21 });2223program24 .command('deploy')25 .description('deploy web site to production')26 .action(() => {27 console.log('deploy');28 });2930program31 .command('serve', { isDefault: true })32 .description('launch web server')33 .option('-p,--port <port_number>', 'web port')

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

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

Parse rework for nested commands (#1149)John Geebefore adoption1345f98

lines 36–38why, one step back
36 });
3738program.parse(process.argv);