mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-28 10:20:09 +00:00
tweaking and notes....
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
4bfc2b19de
commit
33e4afce60
9
argv.js
9
argv.js
@ -1096,6 +1096,8 @@ object.Constructor('Parser', {
|
||||
return res }
|
||||
// NOTE: if successful this needs to modify the arg, thus it
|
||||
// returns both the new first arg and the handler...
|
||||
// XXX if no handler is found this should return the original
|
||||
// input arg...
|
||||
var splitArgs = function(arg, rest){
|
||||
var [arg, value] = arg.split(/=/)
|
||||
// skip single letter unknown or '--' options...
|
||||
@ -1154,15 +1156,12 @@ object.Constructor('Parser', {
|
||||
// dynamic or error...
|
||||
|| parsed.handler(dfl)[1]
|
||||
// no handler found and '-*' or '@*' not defined...
|
||||
if(handler == null){
|
||||
// XXX if nether the whole arg nor it split are found
|
||||
// we need to push the original to unhandled...
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!!', arg)
|
||||
// ...or is setting .splitOptions to false enough???
|
||||
if(handler == null){
|
||||
unhandled.push(arg)
|
||||
continue }
|
||||
//throw module.ParserError(
|
||||
// `Unknown ${ type == 'opt' ? 'option' : 'command:' } $ARG`,
|
||||
// arg) }
|
||||
|
||||
// mark/unmark handlers...
|
||||
values.delete(handler)
|
||||
|
||||
@ -18,26 +18,38 @@ var argv = require('../argv')
|
||||
// ...this can be implemented as a special method/command
|
||||
// something like .next(..) or .handleRest(..)
|
||||
// - .chain(<parser>)
|
||||
//
|
||||
// XXX might be a good idea to flip this around and instead of
|
||||
// chaining after do a pre-parse....
|
||||
var parser =
|
||||
exports.parser =
|
||||
argv.Parser({
|
||||
|
||||
'-x': {
|
||||
handler: function(){
|
||||
console.log('### high priority option') }},
|
||||
|
||||
// setup...
|
||||
// XXX can we go without this???
|
||||
splitOptions: false,
|
||||
|
||||
// pass help through to the chained parser...
|
||||
'-help': undefined,
|
||||
|
||||
// let all the unknown options pass through...
|
||||
'-*': undefined,
|
||||
})
|
||||
// XXX this works but we still need:
|
||||
// - threading back the results
|
||||
// - -help
|
||||
// XXX would also be interesting to be able to route to specific
|
||||
// chained parsers...
|
||||
.then(argv.Parser({
|
||||
'-moo': {
|
||||
handler: function(){
|
||||
console.log('MOO!!!') }},
|
||||
// used for documentation...
|
||||
//
|
||||
// this is handled in the root parser and will never get reached
|
||||
// here...
|
||||
'-x': {
|
||||
doc: [
|
||||
'high priority option',
|
||||
'this will get processed before',
|
||||
'any other options']},
|
||||
}))
|
||||
|
||||
// run the parser...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user