positional-options.js
This file
Path
examples/positional-options.js
23 lines · 731 bytes · JavaScript
Last changed by
Reformat code with Prettier (#2180)John Geebefore adoption1bdc749
History of this fileTake 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 back1#!/usr/bin/env node2Use standard import in examples (#2168)John Geebefore adoption41b12cf
line 3why, one step back3const { Command } = require('commander');Add more tests for implies (#1730)John Geebefore adoption3103c6b
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 more tests for implies (#1730)John Geebefore adoption3103c6b
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