mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-28 18:30:07 +00:00
fixed root value handling...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
6c18c1b3a6
commit
e4a06832c5
22
argv.js
22
argv.js
@ -160,7 +160,6 @@ var afterCallback = function(name){
|
||||
// NOTE: essentially this parser is a very basic stack language...
|
||||
// XXX can we implement the whole thing directly as a stack language???
|
||||
//
|
||||
// XXX need to handle values (and return values) of nested parsers correctly...
|
||||
// XXX can we add more prefexes, like '+' and the like???
|
||||
// XXX might be a good idea to read metadata from package.json
|
||||
// XXX should -help should work for any command?
|
||||
@ -191,8 +190,9 @@ object.Constructor('Parser', {
|
||||
|
||||
// instance stuff...
|
||||
argv: null,
|
||||
pre_argv: null,
|
||||
preArgv: null,
|
||||
rest: null,
|
||||
rootValue: null,
|
||||
|
||||
scriptNmae: null,
|
||||
scriptPath: null,
|
||||
@ -607,7 +607,7 @@ object.Constructor('Parser', {
|
||||
rest.unshift(main) }
|
||||
// normalize the argv...
|
||||
if(main != null){
|
||||
parsed.pre_argv = rest.splice(0, rest.indexOf(main))
|
||||
parsed.preArgv = rest.splice(0, rest.indexOf(main))
|
||||
rest.includes(main)
|
||||
|| rest.unshift(main) }
|
||||
// script stuff...
|
||||
@ -643,7 +643,7 @@ object.Constructor('Parser', {
|
||||
&& parsed.handleArgumentValue) ?
|
||||
parsed.handleArgumentValue(handler, value)
|
||||
: value
|
||||
// required value ...
|
||||
// required value check...
|
||||
if(handler.valueRequired && value == null){
|
||||
handleError('value missing', arg, rest)
|
||||
parsed.printError('value missing:', arg+'=?')
|
||||
@ -659,6 +659,11 @@ object.Constructor('Parser', {
|
||||
[value]
|
||||
: []))
|
||||
|
||||
// add nested parser result parsed...
|
||||
// XXX should this be done also for .STOP / .ERROR / ... ???
|
||||
handler instanceof Parser
|
||||
&& parsed.handlerDefault(handler, rest, arg, res)
|
||||
|
||||
res === module.STOP
|
||||
&& parsed.stop(arg, rest)
|
||||
res === module.ERROR
|
||||
@ -766,9 +771,12 @@ object.Constructor('Parser', {
|
||||
return parsed }
|
||||
|
||||
// handle root value...
|
||||
root_value = (root_value && parsed.handleArgumentValue) ?
|
||||
parsed.handleArgumentValue(parsed, root_value)
|
||||
: root_value
|
||||
root_value =
|
||||
(root_value && parsed.handleArgumentValue) ?
|
||||
parsed.handleArgumentValue(parsed, root_value)
|
||||
: root_value
|
||||
root_value
|
||||
&& (parsed.rootValue = root_value)
|
||||
|
||||
parsed.then(unhandled, root_value, rest)
|
||||
return parsed },
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "ig-argv",
|
||||
"version": "2.2.0",
|
||||
"version": "2.2.2",
|
||||
"description": "simple argv parser",
|
||||
"main": "argv.js",
|
||||
"scripts": {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user