mirror of
https://github.com/flynx/argv.js.git
synced 2025-12-17 17:11:39 +00:00
minor tweaks and docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
493db8fbf6
commit
54451e0451
36
README.md
36
README.md
@ -64,11 +64,7 @@ This code is an evolution of that parser.
|
|||||||
- [`.license`](#license)
|
- [`.license`](#license)
|
||||||
- [`.examples`](#examples)
|
- [`.examples`](#examples)
|
||||||
- [`.footer`](#footer)
|
- [`.footer`](#footer)
|
||||||
- [Help formatting](#help-formatting)
|
- [More control over help...](#more-control-over-help)
|
||||||
- [`.helpColumnOffset`](#helpcolumnoffset)
|
|
||||||
- [`.helpColumnPrefix`](#helpcolumnprefix)
|
|
||||||
- [`.helpArgumentSeparator`](#helpargumentseparator)
|
|
||||||
- [`.helpValueSeparator`](#helpvalueseparator)
|
|
||||||
- [Nested parsers](#nested-parsers)
|
- [Nested parsers](#nested-parsers)
|
||||||
- [Components and API](#components-and-api)
|
- [Components and API](#components-and-api)
|
||||||
- [`THEN`, `STOP` and `ERROR`](#then-stop-and-error)
|
- [`THEN`, `STOP` and `ERROR`](#then-stop-and-error)
|
||||||
@ -84,6 +80,7 @@ This code is an evolution of that parser.
|
|||||||
- [`.handleArgument(..)`](#handleargument)
|
- [`.handleArgument(..)`](#handleargument)
|
||||||
- [`.handleArgumentValue(..)`](#handleargumentvalue)
|
- [`.handleArgumentValue(..)`](#handleargumentvalue)
|
||||||
- [`.handleErrorExit(..)`](#handleerrorexit)
|
- [`.handleErrorExit(..)`](#handleerrorexit)
|
||||||
|
- [More...](#more)
|
||||||
- [License](#license-1)
|
- [License](#license-1)
|
||||||
|
|
||||||
|
|
||||||
@ -118,14 +115,16 @@ var parser = argv.Parser({
|
|||||||
})
|
})
|
||||||
|
|
||||||
// run the parser...
|
// run the parser...
|
||||||
if(__filename == require.main){
|
__filename == require.main
|
||||||
parser(process.argv) }
|
&& parser(process.argv)
|
||||||
```
|
```
|
||||||
|
|
||||||
Option definitions in a bit more detail
|
Option definitions in a bit more detail
|
||||||
```javascript
|
```javascript
|
||||||
var parser = argv.Parser({
|
var parser = argv.Parser({
|
||||||
// basic/quick-n-dirty option...
|
// XXX config...
|
||||||
|
|
||||||
|
// basic quick-n-dirty option...
|
||||||
'-b': '-basic',
|
'-b': '-basic',
|
||||||
'-basic': function(opts, key, value){
|
'-basic': function(opts, key, value){
|
||||||
// ...
|
// ...
|
||||||
@ -184,6 +183,8 @@ var parser = argv.Parser({
|
|||||||
}).then(function(){
|
}).then(function(){
|
||||||
// ...
|
// ...
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
// ...
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -316,19 +317,10 @@ Aditional information.
|
|||||||
|
|
||||||
Default value: `undefined`
|
Default value: `undefined`
|
||||||
|
|
||||||
#### Help formatting
|
|
||||||
|
|
||||||
##### `.helpColumnOffset`
|
#### More control over help...
|
||||||
Default value: `3`
|
|
||||||
|
|
||||||
##### `.helpColumnPrefix`
|
For more info on help formatting see `.help*` attributes in the [source](./argv.js).
|
||||||
Default value: `"- "`
|
|
||||||
|
|
||||||
##### `.helpArgumentSeparator`
|
|
||||||
Default value: `", "`
|
|
||||||
|
|
||||||
##### `.helpValueSeparator`
|
|
||||||
Default value: `" "`
|
|
||||||
|
|
||||||
|
|
||||||
### Nested parsers
|
### Nested parsers
|
||||||
@ -354,6 +346,8 @@ Parser(<spec>)
|
|||||||
-> <parser>
|
-> <parser>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See [`<parser>(..)`](#parser-1) for more info.
|
||||||
|
|
||||||
#### `.then(..)`
|
#### `.then(..)`
|
||||||
|
|
||||||
Add callback to `then` "event".
|
Add callback to `then` "event".
|
||||||
@ -447,6 +441,10 @@ its head.
|
|||||||
|
|
||||||
### `.handleErrorExit(..)`
|
### `.handleErrorExit(..)`
|
||||||
|
|
||||||
|
### More...
|
||||||
|
|
||||||
|
For more info see the [source](./argv.js).
|
||||||
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|||||||
7
argv.js
7
argv.js
@ -226,9 +226,12 @@ object.Constructor('Parser', {
|
|||||||
splitOptions: true,
|
splitOptions: true,
|
||||||
optionPrefix: '-',
|
optionPrefix: '-',
|
||||||
commandPrefix: '@',
|
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
|
// NOTE: we only care about differentiating an option from a command
|
||||||
// here by design...
|
// here by design...
|
||||||
optionInputPattern: /^--?(.*)$/,
|
optionInputPattern: /^([+-])\1?([^+-].*|)$/,
|
||||||
|
//optionInputPattern: /^(-)-?(.*)$/,
|
||||||
//commandInputPattern: /^([.0-9a-zA-Z*].*)$/,
|
//commandInputPattern: /^([.0-9a-zA-Z*].*)$/,
|
||||||
commandInputPattern: /^([^-].*)$/,
|
commandInputPattern: /^([^-].*)$/,
|
||||||
|
|
||||||
@ -329,7 +332,7 @@ object.Constructor('Parser', {
|
|||||||
key = key.split(/=/).shift()
|
key = key.split(/=/).shift()
|
||||||
// normalize option/command name...
|
// normalize option/command name...
|
||||||
key = this.optionInputPattern.test(key) ?
|
key = this.optionInputPattern.test(key) ?
|
||||||
key.replace(this.optionInputPattern, this.optionPrefix+'$1')
|
key.replace(this.optionInputPattern, this.optionPrefix+'$2')
|
||||||
: !key.startsWith(this.commandPrefix) ?
|
: !key.startsWith(this.commandPrefix) ?
|
||||||
key.replace(this.commandInputPattern, this.commandPrefix+'$1')
|
key.replace(this.commandInputPattern, this.commandPrefix+'$1')
|
||||||
: key
|
: key
|
||||||
|
|||||||
2
test.js
2
test.js
@ -113,7 +113,7 @@ var lang =
|
|||||||
module.lang =
|
module.lang =
|
||||||
argv.Parser({
|
argv.Parser({
|
||||||
// handle both +x and -x
|
// handle both +x and -x
|
||||||
optionInputPattern: /^[+-][+-]?(.*)$/,
|
optionInputPattern: /^([+-])\1?([^+-].*|)$/,
|
||||||
|
|
||||||
// XXX for testing, remove when done...
|
// XXX for testing, remove when done...
|
||||||
'-echo': function(...args){
|
'-echo': function(...args){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user