Skip to content
Myr

positional-options.js

This file

Path

examples/positional-options.js

26 lines · 848 bytes · JavaScript

Last changed by

Make examples more consistent with "Try the following" (#1629)John Geebefore adoption2cc3a36

History of this file

Take it

Positional options (#1427)John Geebefore adoption8ac84ec

lines 1–26why, one step back
1#!/usr/bin/env node
23// const { Command } = require('commander'); // (normal include)4const { Command } = require('../'); // include commander in git clone of commander repo5const program = new Command();67program8 .enablePositionalOptions()9 .option('-p, --progress');1011program12 .command('upload <file>')13 .option('-p, --port <number>', 'port number', 80)14 .action((file, options) => {15 if (program.opts().progress) console.log('Starting upload...');16 console.log(`Uploading ${file} to port ${options.port}`);17 if (program.opts().progress) console.log('Finished upload');18 });1920program.parse();2122// Try the following:23// node positional-options.js upload test.js24// node positional-options.js -p upload test.js25// node positional-options.js upload -p 8080 test.js26// node positional-options.js -p upload -p 8080 test.js