minor fix...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-28 03:39:05 +03:00
parent 3a8ab9508e
commit aa9a08258d
3 changed files with 12 additions and 4 deletions

View File

@ -32,6 +32,7 @@ This code is an evolution of that parser.
- Reasonable defaults: - Reasonable defaults:
- `-help` &ndash; generate and print help - `-help` &ndash; generate and print help
- `-version` &ndash; print version - `-version` &ndash; print version
- `-quiet` &ndash; suppress printing
- `-` &ndash; stop argument processing - `-` &ndash; stop argument processing
- Extensible: - Extensible:
- Hooks for dynamic option/command handling - Hooks for dynamic option/command handling
@ -538,7 +539,8 @@ This will turn quiet mode on.
In quiet mode [`<parser>.print(..)`](#parserprint--parserprinterror) will In quiet mode [`<parser>.print(..)`](#parserprint--parserprinterror) will
not print anything. not print anything.
Passing [`--help`](#-h----help) will disable quiet mode and print normally. Passing [`--help`](#-h----help) or [`--version`](#-v----version) will
disable quiet mode and print normally.
#### `-h` / `--help` #### `-h` / `--help`

10
argv.js
View File

@ -484,8 +484,8 @@ object.Constructor('Parser', {
.replace(/\$VERSION/g, this.version || '0.0.0') .replace(/\$VERSION/g, this.version || '0.0.0')
.replace(/\$SCRIPTNAME/g, this.scriptName) }, .replace(/\$SCRIPTNAME/g, this.scriptName) },
'-h': '-help',
// NOTE: this will set .quiet to false... // NOTE: this will set .quiet to false...
'-h': '-help',
'-help': { '-help': {
doc: 'print this message and exit', doc: 'print this message and exit',
priority: 99, priority: 99,
@ -627,6 +627,7 @@ object.Constructor('Parser', {
// Version... // Version...
// //
// NOTE: this will set .quiet to false...
version: undefined, version: undefined,
'-v': '-version', '-v': '-version',
@ -634,19 +635,24 @@ object.Constructor('Parser', {
doc: 'show $SCRIPTNAME verion and exit', doc: 'show $SCRIPTNAME verion and exit',
priority: 99, priority: 99,
handler: function(){ handler: function(){
this.quiet = false
this.print(this.version || '0.0.0') this.print(this.version || '0.0.0')
return module.STOP }, }, return module.STOP }, },
// Quiet mode... // Quiet mode...
// //
quiet: undefined,
'-q': '-quiet', '-q': '-quiet',
'-quiet': { '-quiet': {
priority: 99, priority: 99,
doc: 'quiet mode', }, doc: 'quiet mode', },
// Stop processing arguments and continue into .then(..) handlers... // Stop argument processing...
//
// This will trigger .then(..) handlers...
// //
// If .then(..) does not handle rest in the nested context then this // If .then(..) does not handle rest in the nested context then this
// context will be returned to the parent context, effectively // context will be returned to the parent context, effectively

View File

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