From f47bdf5ca121e03c20fa18d39e2695aa31a15c51 Mon Sep 17 00:00:00 2001 From: John Gee Date: Wed, 29 Jul 2020 10:31:50 +1200 Subject: [PATCH] Tidy up example now check for required command arguments (#1320) --- Readme.md | 11 ++--------- examples/env | 13 +++---------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/Readme.md b/Readme.md index 577a16396..7f9e110e0 100644 --- a/Readme.md +++ b/Readme.md @@ -376,18 +376,11 @@ program .version('0.1.0') .arguments(' [env]') .action(function (cmd, env) { - cmdValue = cmd; - envValue = env; + console.log('command:', cmdValue); + console.log('environment:', envValue || 'no environment given'); }); program.parse(process.argv); - -if (typeof cmdValue === 'undefined') { - console.error('no command given!'); - process.exit(1); -} -console.log('command:', cmdValue); -console.log('environment:', envValue || "no environment given"); ``` The last argument of a command can be variadic, and only the last argument. To make an argument variadic you diff --git a/examples/env b/examples/env index e6b62034a..ba91bfdc4 100755 --- a/examples/env +++ b/examples/env @@ -12,16 +12,9 @@ let envValue; program .version('0.0.1') .arguments(' [env]') - .action(function(cmd, env) { - cmdValue = cmd; - envValue = env; + .action(function(cmdValue, envValue) { + console.log('command:', cmdValue); + console.log('environment:', envValue || 'no environment given'); }); program.parse(process.argv); - -if (typeof cmdValue === 'undefined') { - console.error('no command given!'); - process.exit(1); -} -console.log('command:', cmdValue); -console.log('environment:', envValue || 'no environment given');