docs + fixes to reporting...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-08-02 19:38:36 +03:00
parent ed23022e83
commit 7e9e5e0b5c
3 changed files with 19 additions and 15 deletions

View File

@ -214,17 +214,21 @@ for example:
### Basic options
These, if encountered, simply assign a value to an attribute on the parsed object.
These, if encountered, simply assign a value to an attribute on the parsed object.
This attribute's name is defined by the option name (without the prefix) or by
setting [`<option>.arg`](#optionarg)'s `<key>`.
Any option/command can be passed a value, either explicitly (e.g. `-opt=123`) or
implicitly by first setting `.arg` (see examples below) and and then passing `-opt 123`.
implicitly by first setting [`<option>.arg`](#optionarg)'s `<arg-name>` component
and and then passing `-opt 123`.
Option/command values can be set on the command-line as well as via
[`<option>.env`](./ADVANCED.md#optionenv) and/or
[`<option>.default`](./ADVANCED.md#optiondefault).
If option is given but no value is set, `undefined` is assigned to option
attribute on the parsed object to indicate that the option/command is present
in the command-line.
Note that values can be set on the command-line as well as via
[`<option>.env`](./ADVANCED.md#optionenv) and/or
[`<option>.default`](./ADVANCED.md#optiondefault) see examples below.
Note that repeating a basic option/command will overwrite the previous occurrences'
value unless `.collect` is set (see `-push` example below).

18
argv.js
View File

@ -1005,17 +1005,17 @@ object.Constructor('Parser', {
&& parsed.handleArgumentValue) ?
parsed.handleArgumentValue(handler, value)
: value
// required value check...
if(handler.valueRequired && value == null){
throw module.ParserValueError('Value missing: ${ arg }=?') }
// do not call the handler if value is implicitly undefined...
if(value === undefined
&& mode == 'implicit'){
return }
// run handler...
try {
// required value check...
if(handler.valueRequired && value == null){
throw module.ParserValueError('Value missing: $ARG=?') }
// do not call the handler if value is implicitly undefined...
if(value === undefined
&& mode == 'implicit'){
return }
var res = parsed.handle(handler, rest, arg, value)
// update error object with current context's arg and rest...

View File

@ -1,6 +1,6 @@
{
"name": "ig-argv",
"version": "2.11.0",
"version": "2.11.1",
"description": "simple argv parser",
"main": "argv.js",
"scripts": {