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
40
README.md
40
README.md
@ -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){
|
||||
// ...
|
||||
@ -156,7 +155,7 @@ var parser = argv.Parser({
|
||||
|
||||
// default value (optional)
|
||||
default: 123,
|
||||
|
||||
|
||||
// required status (optional)
|
||||
required: false,
|
||||
|
||||
@ -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
|
||||
@ -346,7 +338,7 @@ Values that if returned by option/command handlers can control the parse flow.
|
||||
- `ERROR` – Stop parsing, call `.error(..)` callbacks and
|
||||
exit with an error.
|
||||
|
||||
### `Parser(..)`
|
||||
### `Parser(..)`
|
||||
|
||||
Construct a parser instance
|
||||
```
|
||||
@ -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
|
||||
|
||||
|
||||
7
argv.js
7
argv.js
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user