Skip to content
Myr

Tidy up example now check for required command arguments (#1320)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by John Gee · committed by GitHub · parent 669190d · Browse files · 2 files+5 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+5 added−19 removed

  • other:+5 added−19 removed

2 files+5 added−19 removed

modified:examples/env+3 added-10 removed
10 unmodified lines
1112program13 .version('0.0.1')14 .arguments('<cmd> [env]')15 .action(function(cmd, env) {16 cmdValue = cmd;17 envValue = env;15 .action(function(cmdValue, envValue) {16 console.log('command:', cmdValue);17 console.log('environment:', envValue || 'no environment given');18 });1920program.parse(process.argv);2122if (typeof cmdValue === 'undefined') {23 console.error('no command given!');24 process.exit(1);25}26console.log('command:', cmdValue);27console.log('environment:', envValue || 'no environment given');
modified:Readme.md+2 added-9 removed
374 unmodified lines
375program376 .version('0.1.0')377 .arguments('<cmd> [env]')378 .action(function (cmd, env) {379 cmdValue = cmd;380 envValue = env;379 console.log('command:', cmdValue);380 console.log('environment:', envValue || 'no environment given');381 });382383program.parse(process.argv);384385if (typeof cmdValue === 'undefined') {386 console.error('no command given!');387 process.exit(1);388}389console.log('command:', cmdValue);390console.log('environment:', envValue || "no environment given");384```385386 The last argument of a command can be variadic, and only the last argument. To make an argument variadic you387 append `...` to the argument name. For example:
389 unmodified lines