positional-options.js
This file
Path
examples/positional-options.js
23 lines · 726 bytes · JavaScript
Last changed by
Switching to esm-only (#2464)John Geebefore adoptionf4bd470
History of this fileTake 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 back1#!/usr/bin/env node2Switching to esm-only (#2464)John Geebefore adoptionf4bd470
line 3why, one step back3import { Command } from 'commander';Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 4–5why, one step back4const program = new Command();5Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
line 6why, one step back6program.enablePositionalOptions().option('-p, --progress');Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40
lines 7–23why, one step back78program9 .command('upload <file>')10 .option('-p, --port <number>', 'port number', 80)11 .action((file, options) => {12 if (program.opts().progress) console.log('Starting upload...');13 console.log(`Uploading ${file} to port ${options.port}`);14 if (program.opts().progress) console.log('Finished upload');15 });1617program.parse();1819// Try the following:20// node positional-options.js upload test.js21// node positional-options.js -p upload test.js22// node positional-options.js upload -p 8080 test.js23// node positional-options.js -p upload -p 8080 test.js