Skip to content
Myr

Tidy up some old examples (#1604)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent 950f742 · Browse files · 4 files+11 added−26 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+11 added−26 removed

  • other:+11 added−26 removed

4 files+11 added−26 removed

modified:examples/custom-help-description+5 added-1 removed
7 unmodified lines
89program10 .helpOption('-c, --HELP', 'custom help message')11 .option('-s, --sessions', 'add session support')12 .option('-t, --template <engine>', 'specify template engine (jade|ejs) [jade]', 'jade');12 .option('-t, --template <engine>', 'specify template engine', 'jade');1314program15 .command('child')16 .option('--gender', 'specific gender of child')
1 unmodified line
18 console.log('Childsubcommand...');19 });2021program.parse(process.argv);2223// Try the following:24// node custom-help-description -c25// node custom-help-description child --HELP
modified:examples/custom-version+5 added-1 removed
7 unmodified lines
89program10 .version('0.0.1', '-v, --VERSION', 'new version message')11 .option('-s, --sessions', 'add session support')12 .option('-t, --template <engine>', 'specify template engine (jade|ejs) [jade]', 'jade');12 .option('-t, --template <engine>', 'specify template engine', 'jade');1314program.parse(process.argv);1516// Try the following:17// node custom-version -v18// node custom-version --VERSION
deleted:examples/defaults-23 removed
1#!/usr/bin/env node23// This example shows adding default values for options.45// const { Command } = require('commander'); // (normal include)6const { Command } = require('../'); // include commander in git clone of commander repo7const program = new Command();89function list(val) {10 return val.split(',').map(Number);11}1213program14 .version('0.0.1')15 .option('-t, --template-engine [engine]', 'Add template [engine] support', 'jade')16 .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')17 .option('-l, --list [items]', 'Specify list items defaulting to 1,2,3', list, [1, 2, 3]);1819program.parse(process.argv);2021console.log(' - %s template engine', program.templateEngine);22console.log(' - %s cheese', program.cheese);23console.log(' - %j', program.list);
modified:examples/pm-install+1 added-1 removed
15 unmodified lines
16 process.exit(1);17}1819console.log();20if (program.force) console.log(' force: install');20if (program.opts().force) console.log(' force: install');21pkgs.forEach(function(pkg) {22 console.log(' install : %s', pkg);23});24console.log();