custom-command-class.js
This file
Path
examples/custom-command-class.js
50 lines · 1.5 KiB · JavaScript
Last changed by
Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
History of this fileTake it
The walk stopped after 200 commits: lines older than 5173665 point at it.
Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
lines 1–7why, one step back1#!/usr/bin/env node23// const commander = require('commander'); // (normal include)4const commander = require('../'); // include commander in git clone of commander repo56// Use a class override to customise the command and its subcommands.7Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 8why, one step back8class CommandWithTrace extends commander.Command {Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
line 9why, one step back9 createCommand(name) {Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
lines 10–13why, one step back10 const cmd = new CommandWithTrace(name);11 // Add an option to subcommands created using `.command()`12 cmd.option('-t, --trace', 'display extra information when run command');13 return cmd;Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
lines 14–16why, one step back14 }15};16Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 17why, one step back17function inpectCommand(command) {Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
line 18why, one step back18 // The option value is stored as property on command because we called .storeOptionsAsProperties()Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 19why, one step back19 console.log(`Called '${command.name()}'`);Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
line 20why, one step back20 console.log(`args: ${command.args}`);Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
line 21why, one step back21 console.log('opts: %o', command.opts());Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
lines 22–23why, one step back22};23Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
lines 24–27why, one step back24const program = new CommandWithTrace('program')25 .option('-v, ---verbose')26 .action((options, command) => {27 inpectCommand(command);Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
lines 28–30why, one step back28 });2930programMake new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
lines 31–34why, one step back31 .command('serve [params...]')32 .option('-p, --port <number>', 'port number')33 .action((params, options, command) => {34 inpectCommand(command);Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
lines 35–36why, one step back35 });36Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
lines 37–42why, one step back37program38 .command('build <target>')39 .action((buildTarget, options, command) => {40 inpectCommand(command);41 });42Simplify eslint dependencies for TypeScript (#1425)John Geebefore adoption5173665
lines 43–45why, one step back43program.parse();4445// Try the following:Make new excess arguments error opt-in (#1429)John Geebefore adoptione2670f4
lines 46–50why, one step back46// node custom-command-class.js --help47// node custom-command-class.js serve --help48// node custom-command-class.js serve -t -p 80 a b c49// node custom-command-class.js build --help50// node custom-command-class.js build --trace foo