global-options-nested.js
This file
Path
examples/global-options-nested.js
28 lines · 811 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake it
Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 1–8why, one step back1#!/usr/bin/env node23// This example shows global options on the program which affect all the subcommands.4// See how to work with global options in the subcommand and display them in the help.5//6// (A different pattern for a "global" option is to add it to the subcommands, rather7// than to the program. See global-options-added.js.)8Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 9why, one step back9import { Command } from 'commander';Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 10–11why, one step back10const program = new Command();11Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 12why, one step back12program.configureHelp({ showGlobalOptions: true }).option('-g, --global');Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 13–19why, one step back1314program15 .command('sub')16 .option('-l, --local')17 .action((options, cmd) => {18 console.log({19 opts: cmd.opts(),Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 20why, one step back20 optsWithGlobals: cmd.optsWithGlobals(),Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631
lines 21–28why, one step back21 });22 });2324program.parse();2526// Try the following:27// node global-options-nested.js --global sub --local28// node global-options-nested.js sub --help