mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-29 02:40:07 +00:00
notes...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
edaefa191a
commit
493db8fbf6
17
argv.js
17
argv.js
@ -195,6 +195,15 @@ var afterCallback = function(name, pre, post){
|
|||||||
// ...manually this is trivial, automating it would complicate things,
|
// ...manually this is trivial, automating it would complicate things,
|
||||||
// will think about it when we need this feature more than once...
|
// will think about it when we need this feature more than once...
|
||||||
// XXX FEATURE (DELAYED): multiple prefixes, like '+' and the like...
|
// XXX FEATURE (DELAYED): multiple prefixes, like '+' and the like...
|
||||||
|
// ...one way to do this manualy now is to set the appropriate
|
||||||
|
// .optionInputPattern and handle the arg in the handler itself...
|
||||||
|
// ...not sure yet how to automate this:
|
||||||
|
// - prefix handler -- pass the prefix to a special handler and
|
||||||
|
// it decides what to do...
|
||||||
|
// -help -> this.handlePrefix('-', ...)
|
||||||
|
// - option prefix derived from arg prefix i.e.
|
||||||
|
// -help -> this['-help'](..)
|
||||||
|
// +help -> this['+help'](..)
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// XXX should -help should work for any command? ..not just nested parsers?
|
// XXX should -help should work for any command? ..not just nested parsers?
|
||||||
@ -596,7 +605,7 @@ object.Constructor('Parser', {
|
|||||||
&& process.exit(1) },
|
&& process.exit(1) },
|
||||||
|
|
||||||
|
|
||||||
// post parsing callbacks...
|
// Post parsing callbacks...
|
||||||
//
|
//
|
||||||
// .then(callback(unhandleed, root_value, rest))
|
// .then(callback(unhandleed, root_value, rest))
|
||||||
//
|
//
|
||||||
@ -607,7 +616,7 @@ object.Constructor('Parser', {
|
|||||||
stop: afterCallback('stop'),
|
stop: afterCallback('stop'),
|
||||||
error: afterCallback('error'),
|
error: afterCallback('error'),
|
||||||
|
|
||||||
// remove callback...
|
// Remove callback...
|
||||||
off: function(evt, handler){
|
off: function(evt, handler){
|
||||||
var l = this['__after_'+evt]
|
var l = this['__after_'+evt]
|
||||||
var i = l.indexOf(handler)
|
var i = l.indexOf(handler)
|
||||||
@ -616,6 +625,7 @@ object.Constructor('Parser', {
|
|||||||
return this },
|
return this },
|
||||||
|
|
||||||
|
|
||||||
|
// Handle the arguments...
|
||||||
//
|
//
|
||||||
// parser()
|
// parser()
|
||||||
// -> result
|
// -> result
|
||||||
@ -626,6 +636,7 @@ object.Constructor('Parser', {
|
|||||||
// parser(argv, main)
|
// parser(argv, main)
|
||||||
// -> result
|
// -> result
|
||||||
//
|
//
|
||||||
|
//
|
||||||
// NOTE: the result is an object inherited from parser and containing
|
// NOTE: the result is an object inherited from parser and containing
|
||||||
// all the parse data...
|
// all the parse data...
|
||||||
// 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
|
||||||
@ -737,7 +748,7 @@ object.Constructor('Parser', {
|
|||||||
var handler = parsed.handler(a)[1]
|
var handler = parsed.handler(a)[1]
|
||||||
return [a, handler] }
|
return [a, handler] }
|
||||||
|
|
||||||
// parse the arguments and call handlers...
|
// parse/interpret the arguments and call handlers...
|
||||||
var values = new Set()
|
var values = new Set()
|
||||||
var seen = new Set()
|
var seen = new Set()
|
||||||
var unhandled = parsed.unhandled = []
|
var unhandled = parsed.unhandled = []
|
||||||
|
|||||||
7
test.js
7
test.js
@ -112,6 +112,13 @@ argv.Parser({
|
|||||||
var lang =
|
var lang =
|
||||||
module.lang =
|
module.lang =
|
||||||
argv.Parser({
|
argv.Parser({
|
||||||
|
// handle both +x and -x
|
||||||
|
optionInputPattern: /^[+-][+-]?(.*)$/,
|
||||||
|
|
||||||
|
// XXX for testing, remove when done...
|
||||||
|
'-echo': function(...args){
|
||||||
|
console.log('ECHO:', ...args)},
|
||||||
|
|
||||||
// helpers...
|
// helpers...
|
||||||
push: function(...items){
|
push: function(...items){
|
||||||
this.unhandled.splice(this.unhandled.length, 0, ...items)
|
this.unhandled.splice(this.unhandled.length, 0, ...items)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user