Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-17 00:01:47 +03:00
parent 3ee263ee14
commit edaefa191a

View File

@ -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...
// ...
})
.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', '-b': '-basic',
'-basic': function(){ '-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,
@ -144,18 +180,11 @@ var parser = argv.Parser({
// nested parser... // nested parser...
'@nested': argv.Parser({ '@nested': argv.Parser({
// ... // ...
}).then(function(){ }).then(function(){
// ... // ...
}), }),
}) })
.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: