From 4fc2e7fc5d365edbd41853f3c6b4557fdb53f875 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 31 Jan 2023 16:50:14 +0300 Subject: [PATCH] better docs + minor cleanup... Signed-off-by: Alex A. Naanou --- ADVANCED.md | 14 +++++++++++++- argv.js | 4 ++-- package.json | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ADVANCED.md b/ADVANCED.md index 7768f72..d51c2c9 100644 --- a/ADVANCED.md +++ b/ADVANCED.md @@ -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) - [`-` / `--`](#-----) - [`-*` / `@*`](#---) + - [`.delegateUnknownToParent`](#parserdelegateunknowntoparent) - [`-v` / `--version`](#-v----version) - [`-q` / `--quiet`](#-q----quiet) - [`-h` / `--help`](#-h----help) @@ -383,11 +384,22 @@ for example. 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 `-*`. +##### `.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` This will output the value of `.version` and exit. diff --git a/argv.js b/argv.js index 0acb98d..4e885b2 100644 --- a/argv.js +++ b/argv.js @@ -1082,8 +1082,8 @@ object.Constructor('Parser', { //section_doc: ..., handler: function(_, key, value){ // delegate to parent... - if(this.delegateUnknownToParent - && this.parent){ + if(this.parent + && this.delegateUnknownToParent){ this.parent.rest.unshift( value === undefined ? key diff --git a/package.json b/package.json index d8294ec..da4f9a9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-argv", - "version": "2.17.0", + "version": "2.17.1", "description": "simple argv parser", "main": "argv.js", "scripts": {