mirror of
https://github.com/flynx/argv.js.git
synced 2025-12-19 10:01:41 +00:00
docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
3ee263ee14
commit
edaefa191a
49
README.md
49
README.md
@ -36,6 +36,12 @@ This code is an evolution of that parser.
|
|||||||
- Hooks for dynamic option/command handling
|
- Hooks for dynamic option/command handling
|
||||||
- Customizable error and stop condition handling
|
- Customizable error and stop condition handling
|
||||||
|
|
||||||
|
## Planned Features
|
||||||
|
|
||||||
|
- Run `<command>-<sub-command>` scripts
|
||||||
|
- Multiple option prefix support
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<!-- XXX ### Alternatives -->
|
<!-- XXX ### Alternatives -->
|
||||||
|
|
||||||
@ -43,6 +49,7 @@ This code is an evolution of that parser.
|
|||||||
- [argv.js](#argvjs)
|
- [argv.js](#argvjs)
|
||||||
- [Motivation](#motivation)
|
- [Motivation](#motivation)
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
|
- [Planned Features](#planned-features)
|
||||||
- [Contents](#contents)
|
- [Contents](#contents)
|
||||||
- [Installation](#installation)
|
- [Installation](#installation)
|
||||||
- [Basic usage](#basic-usage)
|
- [Basic usage](#basic-usage)
|
||||||
@ -102,25 +109,54 @@ Now for the code
|
|||||||
var argv = require('ig-argv')
|
var argv = require('ig-argv')
|
||||||
|
|
||||||
var parser = argv.Parser({
|
var parser = argv.Parser({
|
||||||
// basic/quick option...
|
// option definitions...
|
||||||
'-b': '-basic',
|
|
||||||
'-basic': function(){
|
|
||||||
// ...
|
// ...
|
||||||
|
})
|
||||||
|
.then(function(){
|
||||||
|
// things to do after the options are handled...
|
||||||
|
// ...
|
||||||
|
})
|
||||||
|
|
||||||
|
// run the parser...
|
||||||
|
if(__filename == require.main){
|
||||||
|
parser(process.argv) }
|
||||||
|
```
|
||||||
|
|
||||||
|
Option definitions in a bit more detail
|
||||||
|
```javascript
|
||||||
|
var parser = argv.Parser({
|
||||||
|
// basic/quick-n-dirty option...
|
||||||
|
'-b': '-basic',
|
||||||
|
'-basic': function(opts, key, value){
|
||||||
|
// ...
|
||||||
|
},
|
||||||
|
|
||||||
|
// basic value-getter option...
|
||||||
|
'-value': {
|
||||||
|
doc: 'Value option',
|
||||||
|
arg: 'X | x',
|
||||||
},
|
},
|
||||||
|
|
||||||
// full option settings...
|
// full option settings...
|
||||||
'-f': '-full',
|
'-f': '-full',
|
||||||
'-full': {
|
'-full': {
|
||||||
|
// option doc (optional)
|
||||||
doc: 'Option help',
|
doc: 'Option help',
|
||||||
|
|
||||||
// option value to be displayed in help (optional)
|
// option value to be displayed in help (optional)
|
||||||
// NOTE: "attr" is used as a key to set the value if .handler
|
// NOTE: "attr" is used as a key to set the value if .handler
|
||||||
// was not defined and is ingored in all other cases...
|
// was not defined and is ingored in all other cases...
|
||||||
arg: 'VALUE | attr',
|
arg: 'VALUE | attr',
|
||||||
|
|
||||||
|
// value type handler (optional)
|
||||||
|
type: 'int',
|
||||||
|
|
||||||
// envioroment value (optional)
|
// envioroment value (optional)
|
||||||
env: 'VALUE',
|
env: 'VALUE',
|
||||||
|
|
||||||
// default value (optional)
|
// default value (optional)
|
||||||
default: 123,
|
default: 123,
|
||||||
|
|
||||||
// required status (optional)
|
// required status (optional)
|
||||||
required: false,
|
required: false,
|
||||||
|
|
||||||
@ -149,13 +185,6 @@ var parser = argv.Parser({
|
|||||||
// ...
|
// ...
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.then(function(){
|
|
||||||
// XXX
|
|
||||||
})
|
|
||||||
|
|
||||||
// run the parser only if script.js is run directly...
|
|
||||||
if(__filename == require.main){
|
|
||||||
parser(process.argv) }
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This will create a parser that supports the folowing:
|
This will create a parser that supports the folowing:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user