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 fileTake it
123456789101112131415161718192021222324#!/usr/bin/env node
// This example shows specifying the command arguments using argument() function.
import { Command } from 'commander';const program = new Command();
program .name('connect') .argument('<server>', 'connect to the specified server') .argument('[user]', 'user account for connection', 'guest') .description('Example program with argument descriptions') .action((server, user) => { console.log('server:', server); console.log('user:', user); });
program.parse();
// Try the following:// node argument.js --help// node argument.js main.remote.site// node argument.js main.remote.site admin