Skip to content
Myr

global-options-nested.js

This file

Path

examples/global-options-nested.js

32 lines · 933 bytes · JavaScript

Last changed by

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

History of this file

Take it

Merge branch 'master' into release/10.xJohn Geebefore adoption2bdd631

lines 1–32why, one step back
1#!/usr/bin/env node
23// 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.)89// const { Command } = require('commander'); // (normal include)10const { Command } = require('../'); // include commander in git clone of commander repo1112const program = new Command();1314program15 .configureHelp({ showGlobalOptions: true })16 .option('-g, --global');1718program19 .command('sub')20 .option('-l, --local')21 .action((options, cmd) => {22 console.log({23 opts: cmd.opts(),24 optsWithGlobals: cmd.optsWithGlobals()25 });26 });2728program.parse();2930// Try the following:31// node global-options-nested.js --global sub --local32// node global-options-nested.js sub --help