mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-29 10:50:06 +00:00
docs...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
51d0aae474
commit
b0baf7e7f8
62
argv.js
62
argv.js
@ -78,6 +78,7 @@ var afterCallbackCall = function(name, context, ...args){
|
|||||||
// - arg value type conversion???
|
// - arg value type conversion???
|
||||||
// - make this a constructor???
|
// - make this a constructor???
|
||||||
// - extend this to support command calling...
|
// - extend this to support command calling...
|
||||||
|
// XXX should we handle <scriptName>-<command> script calls???
|
||||||
// XXX do we handle = for options with values???
|
// XXX do we handle = for options with values???
|
||||||
// XXX move this to it's own lib...
|
// XXX move this to it's own lib...
|
||||||
// argv-handler
|
// argv-handler
|
||||||
@ -283,6 +284,62 @@ function(spec){
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
// Parser(spec)
|
||||||
|
// -> parser
|
||||||
|
//
|
||||||
|
// spec format:
|
||||||
|
// {
|
||||||
|
// // option alias...
|
||||||
|
// '-v': '-verbose',
|
||||||
|
// // options handler (basic)...
|
||||||
|
// '-verbose': function(opts, key, value){
|
||||||
|
// ...
|
||||||
|
// },
|
||||||
|
//
|
||||||
|
// // option handler (full)...
|
||||||
|
// // NOTE: the same attributes (except for .handler) can be set on
|
||||||
|
// // the function handler above to same effect...
|
||||||
|
// '-t': '-test',
|
||||||
|
// '-test': {
|
||||||
|
// doc: 'test option.',
|
||||||
|
// arg: 'VALUE',
|
||||||
|
// handler: function(opts, key, value){
|
||||||
|
// ...
|
||||||
|
// }},
|
||||||
|
//
|
||||||
|
// // command...
|
||||||
|
// //
|
||||||
|
// // NOTE: commands are the same as options in every way other than
|
||||||
|
// // call syntax.
|
||||||
|
// // NOTE: it is possible to alias options to commands and vice-versa...
|
||||||
|
// '@command': ... ,
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// // nested parsers...
|
||||||
|
// //
|
||||||
|
// // NOTE: the nested parser behaves the same as if it was root and
|
||||||
|
// // can consume as many argv elements as it needs, effectively
|
||||||
|
// // rendering the relevant options as context sensitive, e.g.:
|
||||||
|
// // cmd -h # get root help...
|
||||||
|
// // cmd nest -h # get help for @nest command...
|
||||||
|
// // NOTE: a nested parser can be either an option or a command...
|
||||||
|
// @nest: new Parser({
|
||||||
|
// doc: 'nested parser',
|
||||||
|
//
|
||||||
|
// '-nested-option': {
|
||||||
|
// ...
|
||||||
|
// },
|
||||||
|
// })
|
||||||
|
// .then(function(){
|
||||||
|
// ...
|
||||||
|
// }),
|
||||||
|
//
|
||||||
|
// ...
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// XXX should we handle <scriptName>-<command> script calls???
|
||||||
var Parser =
|
var Parser =
|
||||||
module.Parser =
|
module.Parser =
|
||||||
object.Constructor('Parser', {
|
object.Constructor('Parser', {
|
||||||
@ -498,6 +555,10 @@ object.Constructor('Parser', {
|
|||||||
stop: afterCallback('stop'),
|
stop: afterCallback('stop'),
|
||||||
error: afterCallback('error'),
|
error: afterCallback('error'),
|
||||||
|
|
||||||
|
//
|
||||||
|
// parser(argv)
|
||||||
|
// -> unprocessed
|
||||||
|
//
|
||||||
// NOTE: this (i.e. parser) can be used as a nested command/option
|
// NOTE: this (i.e. parser) can be used as a nested command/option
|
||||||
// handler...
|
// handler...
|
||||||
__call__: function(context, argv){
|
__call__: function(context, argv){
|
||||||
@ -579,6 +640,7 @@ object.Constructor('Parser', {
|
|||||||
afterCallbackCall('parsing', this, unhandled)
|
afterCallbackCall('parsing', this, unhandled)
|
||||||
return this },
|
return this },
|
||||||
|
|
||||||
|
// NOTE: see general doc...
|
||||||
__init__: function(spec){
|
__init__: function(spec){
|
||||||
Object.assign(this, spec)
|
Object.assign(this, spec)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user