Skip to content
Myr

pass-through-options.js

This file

Path

examples/pass-through-options.js

22 lines · 633 bytes · JavaScript

Last changed by

Use standard import in examples (#2168)John Geebefore adoption41b12cf

History of this file

Take it

The walk stopped after 200 commits: lines older than 3103c6b point at it.

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 1–2why, one step back
1#!/usr/bin/env node
2

Use standard import in examples (#2168)John Geebefore adoption41b12cf

line 3why, one step back
3const { Command } = require('commander');

Add more tests for implies (#1730)John Geebefore adoption3103c6b

lines 4–22why, one step back
4const program = new Command();
56program7 .argument('<utility>')8 .argument('[args...]')9 .passThroughOptions()10 .option('-d, --dry-run')11 .action((utility, args, options) => {12 const action = options.dryRun ? 'Would run' : 'Running';13 console.log(`${action}: ${utility} ${args.join(' ')}`);14 });1516program.parse();1718// Try the following:19// node pass-through-options.js git status20// node pass-through-options.js git --version21// node pass-through-options.js --dry-run git checkout -b new-branch22// node pass-through-options.js git push --dry-run