added simple multiline option .doc support...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-08-10 23:17:10 +03:00
parent b982314015
commit a36f566f10
5 changed files with 22 additions and 4 deletions

View File

@ -162,6 +162,12 @@ to control further parsing and/or execution.
#### `<option>.doc`
Option/command documentation string used in `-help`.
```
doc: <string> | <array-of-strings>,
```
If an array of strings is given each string will be printed on a separate
line.
If this is set to `false` the option will be hidden from `-help`.

View File

@ -246,7 +246,9 @@ but option context can matter (see: [Active options/commands](#active-optionscom
// option with a value...
'-value': {
doc: 'set .x to X',
doc: [
'set .x to X',
'NOTE: .doc can be multiple lines'],
// 'X' (i.e. VALUE) is used to indicate the option value in -help
// while 'x' (key) is the attribute where the value will be written...
@ -520,6 +522,7 @@ Options:
(default: some value)
--flag - if given set .flag
--value=X - set .x to X
NOTE: .doc can be multiple lines
(required value)
-i=INT - pass an integer value
--home=PATH - set home path

View File

@ -585,6 +585,11 @@ object.Constructor('Parser', {
var val_req = getValue(handler, 'valueRequired')[1]
var env = getValue(handler, 'env')[1]
doc = (doc instanceof Array ?
doc
: [doc])
.map(function(s){
return s.replace(/\\\*/g, '*') })
var info = [
...(req ?
['required']
@ -603,7 +608,9 @@ object.Constructor('Parser', {
[`more: .. ${ arg.slice(1) } -h`]
: []),
].join(', ')
return [doc.replace(/\\\*/g, '*'),
return [
...doc,
...(info.length > 0 ?
['('+ info +')']
: [])] }

View File

@ -22,7 +22,9 @@ argv.Parser({
// option with a value...
'-value': {
doc: 'set .x to X',
doc: [
'set .x to X',
'NOTE: .doc can be multiple lies'],
// 'X' (i.e. VALUE) is used to indicate the option value in -help
// while 'x' (key) is the attribute where the value will be written...

View File

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