positional-options.js
This file
Path
examples/positional-options.js
25 lines · 737 bytes · JavaScript
Last changed by
Use standard import in examples (#2168)John Geebefore adoption41b12cf
History of this fileTake it
The walk stopped after 200 commits: lines older than 0b0fbbe point at it.
Update dependencies (#1524)John Geebefore adoption0b0fbbe
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');Update dependencies (#1524)John Geebefore adoption0b0fbbe
lines 4–25why, one step back4const program = new Command();56program7 .enablePositionalOptions()8 .option('-p, --progress');910program11 .command('upload <file>')12 .option('-p, --port <number>', 'port number', 80)13 .action((file, options) => {14 if (program.opts().progress) console.log('Starting upload...');15 console.log(`Uploading ${file} to port ${options.port}`);16 if (program.opts().progress) console.log('Finished upload');17 });1819program.parse();2021// Try the following:22// node positional-options.js upload test.js23// node positional-options.js -p upload test.js24// node positional-options.js upload -p 8080 test.js25// node positional-options.js -p upload -p 8080 test.js