From 3a8ab9508e945e059bb8dbc42fa58380aa64725f Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 28 Jul 2020 03:31:08 +0300 Subject: [PATCH] added quiet mode... Signed-off-by: Alex A. Naanou --- README.md | 13 ++++++++++++- argv.js | 15 ++++++++++++++- package.json | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ed8eb55..7d164b2 100644 --- a/README.md +++ b/README.md @@ -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) - [`.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 [`.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: diff --git a/argv.js b/argv.js index e66b88c..a0dfa36 100644 --- a/argv.js +++ b/argv.js @@ -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(...) diff --git a/package.json b/package.json index 61f5599..c6a1d2b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-argv", - "version": "2.6.0", + "version": "2.7.0", "description": "simple argv parser", "main": "argv.js", "scripts": {