Comparing version 0.2.6 to 0.2.7
# Changes | ||
## 0.2.7 | ||
* Positional arguments constraints support added, by mean of `_meta_` argument settings. | ||
## 0.2.5 | ||
@@ -4,0 +8,0 @@ |
@@ -250,2 +250,5 @@ 'use strict'; | ||
for (option in config) { | ||
if (option === '_meta_') { | ||
continue; | ||
} | ||
if (config[option].mandatory && !(option in cmdOptions)) { | ||
@@ -275,2 +278,23 @@ if (testing) { | ||
// Check expected positional arguments are provided | ||
var providedArgs = 0; | ||
if (Array.isArray(cmdOptions.args) && cmdOptions.args.length > 0) { | ||
providedArgs = cmdOptions.args.length; | ||
} | ||
if (config._meta_ && config._meta_.args && providedArgs !== config._meta_.args) { | ||
console.log('%d positional arguments (without option flag) are required, but %d have been provided.', config._meta_.args, providedArgs); | ||
printHelpMessage(config, helpTail, programName); | ||
process.exit(-1); | ||
} | ||
if (config._meta_ && config._meta_.minArgs && providedArgs < config._meta_.minArgs) { | ||
console.log('At least %d positional arguments (without option flag) are required, but %d have been provided.', config._meta_.minArgs, providedArgs); | ||
printHelpMessage(config, helpTail, programName); | ||
process.exit(-1); | ||
} | ||
if (config._meta_ && config._meta_.maxArgs && providedArgs > config._meta_.maxArgs) { | ||
console.log('Too many positional arguments (without option flag) provided. The maximum allowed is %d, but %d have been provided.', config._meta_.maxArgs, providedArgs); | ||
printHelpMessage(config, helpTail, programName); | ||
process.exit(-1); | ||
} | ||
// Apply default values | ||
@@ -308,2 +332,5 @@ for (option in config) { | ||
for (o in options) { | ||
if (o === '_meta_') { | ||
continue; | ||
} | ||
if (options.hasOwnProperty(o)) { | ||
@@ -310,0 +337,0 @@ var ops = ' ', i; |
{ | ||
"name": "stdio", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "Standard input/output management with NodeJS", | ||
@@ -5,0 +5,0 @@ "keywords": ["input", "console", "output", "terminal", "system", "arguments", "cli"], |
@@ -96,6 +96,28 @@ Module for standard input/output management with nodejs. | ||
var ops = stdio.getopt({ | ||
meta: {args: 2, default: ['a', 'b']} | ||
something: {args: 2, default: ['a', 'b']} | ||
}); | ||
``` | ||
#### Mandatory positional arguments | ||
If your program has to receive some mandatory positional arguments (extra arguments without an option flag), you can specify it when calling `getopt()`: | ||
``` | ||
var ops = stdio.getopt({ | ||
_meta_: {args: 2} | ||
}); | ||
``` | ||
``` | ||
var ops = stdio.getopt({ | ||
_meta_: {minArgs: 1} | ||
}); | ||
``` | ||
``` | ||
var ops = stdio.getopt({ | ||
_meta_: {maxArgs: 5} | ||
}); | ||
``` | ||
#### Print usage | ||
@@ -102,0 +124,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
37392
790
243