better docs + minor cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2023-01-31 16:50:14 +03:00
parent cfaa901611
commit 4fc2e7fc5d
3 changed files with 16 additions and 4 deletions

View File

@ -28,6 +28,7 @@ For basics see [README.md](./README.md)
- [Disabling or redefining a built-in option](#disabling-or-redefining-a-built-in-option) - [Disabling or redefining a built-in option](#disabling-or-redefining-a-built-in-option)
- [`-` / `--`](#-----) - [`-` / `--`](#-----)
- [`-*` / `@*`](#---) - [`-*` / `@*`](#---)
- [`<parser>.delegateUnknownToParent`](#parserdelegateunknowntoparent)
- [`-v` / `--version`](#-v----version) - [`-v` / `--version`](#-v----version)
- [`-q` / `--quiet`](#-q----quiet) - [`-q` / `--quiet`](#-q----quiet)
- [`-h` / `--help`](#-h----help) - [`-h` / `--help`](#-h----help)
@ -383,11 +384,22 @@ for example.
Handle options/commands for which no definition is found. Handle options/commands for which no definition is found.
By default `-*` will print an "unhandled option/command" error and terminate. By default `-*` will:
- on root parser: print an "unhandled option/command" error and terminate.
- on nested parser: delegate the option to the parent.
By default `@*` is an alias to `-*`. By default `@*` is an alias to `-*`.
##### `<parser>.delegateUnknownToParent`
Controls the default behavior of a nested parser when encountering an unknown option.
If `true` (default) the option will be delegated to the parent parser. If `false`
behave the same way as the root parser, i.e. printing an error.
#### `-v` / `--version` #### `-v` / `--version`
This will output the value of `.version` and exit. This will output the value of `.version` and exit.

View File

@ -1082,8 +1082,8 @@ object.Constructor('Parser', {
//section_doc: ..., //section_doc: ...,
handler: function(_, key, value){ handler: function(_, key, value){
// delegate to parent... // delegate to parent...
if(this.delegateUnknownToParent if(this.parent
&& this.parent){ && this.delegateUnknownToParent){
this.parent.rest.unshift( this.parent.rest.unshift(
value === undefined ? value === undefined ?
key key

View File

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