mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-29 10:50:06 +00:00
more tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6731b64088
commit
fcb541f75d
30
ADVANCED.md
30
ADVANCED.md
@ -35,7 +35,9 @@ For basics see [README.md](./README.md)
|
|||||||
- [Automatically defined values](#automatically-defined-values)
|
- [Automatically defined values](#automatically-defined-values)
|
||||||
- [`<parser>.doc`](#parserdoc)
|
- [`<parser>.doc`](#parserdoc)
|
||||||
- [`<parser>.usage`](#parserusage)
|
- [`<parser>.usage`](#parserusage)
|
||||||
|
- [`<parser>.packageJson`](#parserpackagejson)
|
||||||
- [`<parser>.version`](#parserversion)
|
- [`<parser>.version`](#parserversion)
|
||||||
|
- [`<parser>.author`](#parserauthor)
|
||||||
- [`<parser>.license`](#parserlicense)
|
- [`<parser>.license`](#parserlicense)
|
||||||
- [`<parser>.examples`](#parserexamples)
|
- [`<parser>.examples`](#parserexamples)
|
||||||
- [`<parser>.footer`](#parserfooter)
|
- [`<parser>.footer`](#parserfooter)
|
||||||
@ -460,21 +462,47 @@ Basic usage hint.
|
|||||||
Default value: `"$SCRIPTNAME [OPTIONS]"`
|
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`
|
##### `<parser>.version`
|
||||||
|
|
||||||
Version number.
|
Version number.
|
||||||
|
|
||||||
<spec>.usage = <string> | <function> | undefined
|
<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`
|
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`
|
##### `<parser>.license`
|
||||||
|
|
||||||
Short license information.
|
Short license information.
|
||||||
|
|
||||||
<spec>.usage = <string> | <function> | undefined
|
<spec>.usage = <string> | <function> | undefined
|
||||||
|
|
||||||
|
If not set project metadata is used, if found.
|
||||||
|
|
||||||
Default value: `undefined`
|
Default value: `undefined`
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,7 @@ This code is an evolution of that parser.
|
|||||||
- Option/command value collection
|
- Option/command value collection
|
||||||
- Multiple option prefix support
|
- Multiple option prefix support
|
||||||
- Reasonable defaults:
|
- Reasonable defaults:
|
||||||
|
- Metadata defaults to `package.json`
|
||||||
- `-help` – generate and print help
|
- `-help` – generate and print help
|
||||||
- `-version` – print version
|
- `-version` – print version
|
||||||
- `-quiet` – suppress printing
|
- `-quiet` – suppress printing
|
||||||
@ -198,6 +199,11 @@ Metadata:
|
|||||||
license: 'BSD-3-Clause',
|
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,
|
These basic bits of metadata can be referenced in other `-help` sections,
|
||||||
for example:
|
for example:
|
||||||
```javascript
|
```javascript
|
||||||
|
|||||||
4
argv.js
4
argv.js
@ -137,7 +137,9 @@ function(attr, func){
|
|||||||
return function(p){
|
return function(p){
|
||||||
try {
|
try {
|
||||||
var res = require(p
|
var res = require(p
|
||||||
|| this.packageJson
|
|| (typeof(this.packageJson) == 'function' ?
|
||||||
|
this.packageJson()
|
||||||
|
: this.packageJson)
|
||||||
|| path.dirname(
|
|| path.dirname(
|
||||||
(require.main || {}).filename || '.')
|
(require.main || {}).filename || '.')
|
||||||
+'/package.json')[attr]
|
+'/package.json')[attr]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ig-argv",
|
"name": "ig-argv",
|
||||||
"version": "2.10.2",
|
"version": "2.10.3",
|
||||||
"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