minor tweaks and docs...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-18 20:17:15 +03:00
parent 493db8fbf6
commit 54451e0451
3 changed files with 25 additions and 24 deletions

View File

@ -64,11 +64,7 @@ This code is an evolution of that parser.
- [`.license`](#license)
- [`.examples`](#examples)
- [`.footer`](#footer)
- [Help formatting](#help-formatting)
- [`.helpColumnOffset`](#helpcolumnoffset)
- [`.helpColumnPrefix`](#helpcolumnprefix)
- [`.helpArgumentSeparator`](#helpargumentseparator)
- [`.helpValueSeparator`](#helpvalueseparator)
- [More control over help...](#more-control-over-help)
- [Nested parsers](#nested-parsers)
- [Components and API](#components-and-api)
- [`THEN`, `STOP` and `ERROR`](#then-stop-and-error)
@ -84,6 +80,7 @@ This code is an evolution of that parser.
- [`.handleArgument(..)`](#handleargument)
- [`.handleArgumentValue(..)`](#handleargumentvalue)
- [`.handleErrorExit(..)`](#handleerrorexit)
- [More...](#more)
- [License](#license-1)
@ -118,14 +115,16 @@ var parser = argv.Parser({
})
// run the parser...
if(__filename == require.main){
parser(process.argv) }
__filename == require.main
&& parser(process.argv)
```
Option definitions in a bit more detail
```javascript
var parser = argv.Parser({
// basic/quick-n-dirty option...
// XXX config...
// basic quick-n-dirty option...
'-b': '-basic',
'-basic': function(opts, key, value){
// ...
@ -184,6 +183,8 @@ var parser = argv.Parser({
}).then(function(){
// ...
}),
// ...
})
```
@ -316,19 +317,10 @@ Aditional information.
Default value: `undefined`
#### Help formatting
##### `.helpColumnOffset`
Default value: `3`
#### More control over help...
##### `.helpColumnPrefix`
Default value: `"- "`
##### `.helpArgumentSeparator`
Default value: `", "`
##### `.helpValueSeparator`
Default value: `" "`
For more info on help formatting see `.help*` attributes in the [source](./argv.js).
### Nested parsers
@ -354,6 +346,8 @@ Parser(<spec>)
-> <parser>
```
See [`<parser>(..)`](#parser-1) for more info.
#### `.then(..)`
Add callback to `then` "event".
@ -447,6 +441,10 @@ its head.
### `.handleErrorExit(..)`
### More...
For more info see the [source](./argv.js).
## License

View File

@ -226,9 +226,12 @@ object.Constructor('Parser', {
splitOptions: true,
optionPrefix: '-',
commandPrefix: '@',
// NOTE: this must contain two goups the first is the prefix and the
// second must contain the option name...
// NOTE: we only care about differentiating an option from a command
// here by design...
optionInputPattern: /^--?(.*)$/,
optionInputPattern: /^([+-])\1?([^+-].*|)$/,
//optionInputPattern: /^(-)-?(.*)$/,
//commandInputPattern: /^([.0-9a-zA-Z*].*)$/,
commandInputPattern: /^([^-].*)$/,
@ -329,7 +332,7 @@ object.Constructor('Parser', {
key = key.split(/=/).shift()
// normalize option/command name...
key = this.optionInputPattern.test(key) ?
key.replace(this.optionInputPattern, this.optionPrefix+'$1')
key.replace(this.optionInputPattern, this.optionPrefix+'$2')
: !key.startsWith(this.commandPrefix) ?
key.replace(this.commandInputPattern, this.commandPrefix+'$1')
: key

View File

@ -113,7 +113,7 @@ var lang =
module.lang =
argv.Parser({
// handle both +x and -x
optionInputPattern: /^[+-][+-]?(.*)$/,
optionInputPattern: /^([+-])\1?([^+-].*|)$/,
// XXX for testing, remove when done...
'-echo': function(...args){