Skip to content
Myr

argument.js

This file

Path

examples/argument.js

23 lines · 643 bytes · JavaScript

Last changed by

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

History of this file

Take it

The walk stopped after 200 commits: lines older than 471ec40 point at it.

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 1–4why, one step back
1#!/usr/bin/env node
23// This example shows specifying the command arguments using argument() function.4

Switching to esm-only (#2464)John Geebefore adoptionf4bd470

line 5why, one step back
5import { Command } from 'commander';

Add copyInheritedSettings to README (#1798)John Geebefore adoption471ec40

lines 6–23why, one step back
6const program = new Command();
78program9 .name('connect')10 .argument('<server>', 'connect to the specified server')11 .argument('[user]', 'user account for connection', 'guest')12 .description('Example program with argument descriptions')13 .action((server, user) => {14 console.log('server:', server);15 console.log('user:', user);16 });1718program.parse();1920// Try the following:21// node argument.js --help22// node argument.js main.remote.site23// node argument.js main.remote.site admin