mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-29 02:40:07 +00:00
added quiet mode...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
42a9f46f9c
commit
3a8ab9508e
13
README.md
13
README.md
@ -73,6 +73,7 @@ This code is an evolution of that parser.
|
|||||||
- [`-` / `--`](#-----)
|
- [`-` / `--`](#-----)
|
||||||
- [`-*` / `@*`](#---)
|
- [`-*` / `@*`](#---)
|
||||||
- [`-v` / `--version`](#-v----version)
|
- [`-v` / `--version`](#-v----version)
|
||||||
|
- [`-q` / `--quiet`](#-q----quiet)
|
||||||
- [`-h` / `--help`](#-h----help)
|
- [`-h` / `--help`](#-h----help)
|
||||||
- [Value placeholders](#value-placeholders)
|
- [Value placeholders](#value-placeholders)
|
||||||
- [Automatically defined values](#automatically-defined-values)
|
- [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)
|
- [More control over help...](#more-control-over-help)
|
||||||
- [Nested parsers](#nested-parsers)
|
- [Nested parsers](#nested-parsers)
|
||||||
- [Components and API](#components-and-api)
|
- [Components and API](#components-and-api)
|
||||||
- [`THEN`/ `STOP`](#then-stop)
|
- [`THEN` / `STOP`](#then--stop)
|
||||||
- [`ParserError(..)`](#parsererror)
|
- [`ParserError(..)`](#parsererror)
|
||||||
- [`Parser(..)`](#parser)
|
- [`Parser(..)`](#parser)
|
||||||
- [`<parser>.then(..)`](#parserthen)
|
- [`<parser>.then(..)`](#parserthen)
|
||||||
@ -530,6 +531,16 @@ By default `@*` is an alias to `-*`.
|
|||||||
This will output the value of `.version` and exit.
|
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`
|
#### `-h` / `--help`
|
||||||
|
|
||||||
By default `-help` will output in the following format:
|
By default `-help` will output in the following format:
|
||||||
|
|||||||
15
argv.js
15
argv.js
@ -485,6 +485,7 @@ object.Constructor('Parser', {
|
|||||||
.replace(/\$SCRIPTNAME/g, this.scriptName) },
|
.replace(/\$SCRIPTNAME/g, this.scriptName) },
|
||||||
|
|
||||||
'-h': '-help',
|
'-h': '-help',
|
||||||
|
// NOTE: this will set .quiet to false...
|
||||||
'-help': {
|
'-help': {
|
||||||
doc: 'print this message and exit',
|
doc: 'print this message and exit',
|
||||||
priority: 99,
|
priority: 99,
|
||||||
@ -527,6 +528,9 @@ object.Constructor('Parser', {
|
|||||||
['', title +':', ...items]
|
['', title +':', ...items]
|
||||||
: [] }
|
: [] }
|
||||||
|
|
||||||
|
// ignore quiet mode...
|
||||||
|
this.quiet = false
|
||||||
|
|
||||||
this.print(
|
this.print(
|
||||||
expandVars([
|
expandVars([
|
||||||
`Usage: ${ getValue('usage').join('') }`,
|
`Usage: ${ getValue('usage').join('') }`,
|
||||||
@ -634,6 +638,14 @@ object.Constructor('Parser', {
|
|||||||
return module.STOP }, },
|
return module.STOP }, },
|
||||||
|
|
||||||
|
|
||||||
|
// Quiet mode...
|
||||||
|
//
|
||||||
|
'-q': '-quiet',
|
||||||
|
'-quiet': {
|
||||||
|
priority: 99,
|
||||||
|
doc: 'quiet mode', },
|
||||||
|
|
||||||
|
|
||||||
// Stop processing arguments and continue into .then(..) handlers...
|
// Stop processing arguments and continue into .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
|
||||||
@ -674,7 +686,8 @@ object.Constructor('Parser', {
|
|||||||
// Output...
|
// Output...
|
||||||
//
|
//
|
||||||
print: afterCallback('print', null, function(...args){
|
print: afterCallback('print', null, function(...args){
|
||||||
console.log(...args)
|
this.quiet
|
||||||
|
|| console.log(...args)
|
||||||
return this }),
|
return this }),
|
||||||
//
|
//
|
||||||
// .printError(...)
|
// .printError(...)
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-argv",
|
"name": "ig-argv",
|
||||||
"version": "2.6.0",
|
"version": "2.7.0",
|
||||||
"description": "simple argv parser",
|
"description": "simple argv parser",
|
||||||
"main": "argv.js",
|
"main": "argv.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user