Skip to content
Myr

defaultCommand.js

This file

Path

examples/defaultCommand.js

36 lines · 956 bytes · JavaScript

Last changed by

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

History of this file

Take it

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

lines 1–36why, one step back
1// const commander = require('commander'); // (normal include)
2const commander = require('../'); // include commander in git clone of commander repo3const program = new commander.Command();45// Example program using the command configuration option isDefault to specify the default command.6//7// $ node defaultCommand.js build8// build9// $ node defaultCommand.js serve -p 808010// server on port 808011// $ node defaultCommand.js -p 44312// server on port 4431314program15 .command('build')16 .description('build web site for deployment')17 .action(() => {18 console.log('build');19 });2021program22 .command('deploy')23 .description('deploy web site to production')24 .action(() => {25 console.log('deploy');26 });2728program29 .command('serve', { isDefault: true })30 .description('launch web server')31 .option('-p,--port <port_number>', 'web port')32 .action((opts) => {33 console.log(`server on port ${opts.port}`);34 });3536program.parse(process.argv);