Skip to content
Myr

pass-through-options.js

This file

Path

examples/pass-through-options.js

22 lines · 628 bytes · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

The walk stopped after 200 commits: lines older than 471ec40 point at it.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 3why, one step back
3import { Command } from 'commander';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

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