Skip to content
Myr

defaults

This file

Path

examples/defaults

23 lines · 795 bytes

Last changed by

Merge pull request #1305 from tj/release/6.xTomoaki Abebefore adoptionc5a5e7b

History of this file

Take it

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);