added quiet mode...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-28 03:31:08 +03:00
parent 42a9f46f9c
commit 3a8ab9508e
3 changed files with 27 additions and 3 deletions

View File

@ -73,6 +73,7 @@ This code is an evolution of that parser.
- [`-` / `--`](#-----)
- [`-*` / `@*`](#---)
- [`-v` / `--version`](#-v----version)
- [`-q` / `--quiet`](#-q----quiet)
- [`-h` / `--help`](#-h----help)
- [Value placeholders](#value-placeholders)
- [Automatically defined values](#automatically-defined-values)
@ -85,7 +86,7 @@ This code is an evolution of that parser.
- [More control over help...](#more-control-over-help)
- [Nested parsers](#nested-parsers)
- [Components and API](#components-and-api)
- [`THEN`/ `STOP`](#then-stop)
- [`THEN` / `STOP`](#then--stop)
- [`ParserError(..)`](#parsererror)
- [`Parser(..)`](#parser)
- [`<parser>.then(..)`](#parserthen)
@ -530,6 +531,16 @@ By default `@*` is an alias to `-*`.
This will output the value of `.version` and exit.
#### `-q` / `--quiet`
This will turn quiet mode on.
In quiet mode [`<parser>.print(..)`](#parserprint--parserprinterror) will
not print anything.
Passing [`--help`](#-h----help) will disable quiet mode and print normally.
#### `-h` / `--help`
By default `-help` will output in the following format:

15
argv.js
View File

@ -485,6 +485,7 @@ object.Constructor('Parser', {
.replace(/\$SCRIPTNAME/g, this.scriptName) },
'-h': '-help',
// NOTE: this will set .quiet to false...
'-help': {
doc: 'print this message and exit',
priority: 99,
@ -527,6 +528,9 @@ object.Constructor('Parser', {
['', title +':', ...items]
: [] }
// ignore quiet mode...
this.quiet = false
this.print(
expandVars([
`Usage: ${ getValue('usage').join('') }`,
@ -634,6 +638,14 @@ object.Constructor('Parser', {
return module.STOP }, },
// Quiet mode...
//
'-q': '-quiet',
'-quiet': {
priority: 99,
doc: 'quiet mode', },
// Stop processing arguments and continue into .then(..) handlers...
//
// If .then(..) does not handle rest in the nested context then this
@ -674,7 +686,8 @@ object.Constructor('Parser', {
// Output...
//
print: afterCallback('print', null, function(...args){
console.log(...args)
this.quiet
|| console.log(...args)
return this }),
//
// .printError(...)

View File

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