Skip to content

Commit

Permalink
Tidy up example now check for required command arguments (#1320)
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowspawn committed Jul 28, 2020
1 parent 669190d commit f47bdf5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
11 changes: 2 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,18 +376,11 @@ program
.version('0.1.0')
.arguments('<cmd> [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
Expand Down
13 changes: 3 additions & 10 deletions examples/env
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@ let envValue;
program
.version('0.0.1')
.arguments('<cmd> [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');

0 comments on commit f47bdf5

Please sign in to comment.