pass-through-options.js
This file
Path
examples/pass-through-options.js
23 lines · 744 bytes · JavaScript
Last changed by
Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36
History of this fileTake it
Positional options (#1427)John Geebefore adoption8ac84ec
lines 1–7why, one step back1#!/usr/bin/env node23// const { Command } = require('commander'); // (normal include)4const { Command } = require('../'); // include commander in git clone of commander repo5const program = new Command();67programMore consistent way of adding command arguments (#1490)John Geebefore adoptionb286da9
lines 8–9why, one step back8 .argument('<utility>')9 .argument('[args...]')Positional options (#1427)John Geebefore adoption8ac84ec
lines 10–23why, one step back10 .passThroughOptions()11 .option('-d, --dry-run')12 .action((utility, args, options) => {13 const action = options.dryRun ? 'Would run' : 'Running';14 console.log(`${action}: ${utility} ${args.join(' ')}`);15 });1617program.parse();1819// Try the following:20// node pass-through-options.js git status21// node pass-through-options.js git --version22// node pass-through-options.js --dry-run git checkout -b new-branch23// node pass-through-options.js git push --dry-run