more tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-08-02 07:21:59 +03:00
parent 6731b64088
commit fcb541f75d
4 changed files with 39 additions and 3 deletions

View File

@ -35,7 +35,9 @@ For basics see [README.md](./README.md)
- [Automatically defined values](#automatically-defined-values)
- [`<parser>.doc`](#parserdoc)
- [`<parser>.usage`](#parserusage)
- [`<parser>.packageJson`](#parserpackagejson)
- [`<parser>.version`](#parserversion)
- [`<parser>.author`](#parserauthor)
- [`<parser>.license`](#parserlicense)
- [`<parser>.examples`](#parserexamples)
- [`<parser>.footer`](#parserfooter)
@ -460,21 +462,47 @@ Basic usage hint.
Default value: `"$SCRIPTNAME [OPTIONS]"`
##### `<parser>.packageJson`
The path to the metadata JSON file.
<spec>.packageJson = <string> | <function> | undefined
If not set `package.json` will be searched for in the same directory as the
main script.
Default value: `undefined`.
##### `<parser>.version`
Version number.
<spec>.usage = <string> | <function> | undefined
If this is not defined `-version` will print `"0.0.0"`.
If this is not defined it will be read from the project metadata, if none is
found `"0.0.0"` will be printed by `-version`.
Default value: `undefined`
##### `<parser>.author`
Author name/contacts.
<spec>.author = <string> | <function> | undefined
If not set project metadata is used, if found.
Default value: `undefined`
##### `<parser>.license`
Short license information.
<spec>.usage = <string> | <function> | undefined
If not set project metadata is used, if found.
Default value: `undefined`

View File

@ -30,6 +30,7 @@ This code is an evolution of that parser.
- Option/command value collection
- Multiple option prefix support
- Reasonable defaults:
- Metadata defaults to `package.json`
- `-help` &ndash; generate and print help
- `-version` &ndash; print version
- `-quiet` &ndash; suppress printing
@ -198,6 +199,11 @@ Metadata:
license: 'BSD-3-Clause',
```
If not set, `.version`, `.author`, `.license` are acquired from `package.json`
located at the same path as the main script.
To explicitly set the path of the JSON file from which metadata is read set
`.packageJson`.
These basic bits of metadata can be referenced in other `-help` sections,
for example:
```javascript

View File

@ -137,7 +137,9 @@ function(attr, func){
return function(p){
try {
var res = require(p
|| this.packageJson
|| (typeof(this.packageJson) == 'function' ?
this.packageJson()
: this.packageJson)
|| path.dirname(
(require.main || {}).filename || '.')
+'/package.json')[attr]

View File

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