tweaking and notes....

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-08-26 13:57:46 +03:00
parent 4bfc2b19de
commit 33e4afce60
2 changed files with 24 additions and 13 deletions

11
argv.js
View File

@ -1096,6 +1096,8 @@ object.Constructor('Parser', {
return res } return res }
// NOTE: if successful this needs to modify the arg, thus it // NOTE: if successful this needs to modify the arg, thus it
// returns both the new first arg and the handler... // 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 splitArgs = function(arg, rest){
var [arg, value] = arg.split(/=/) var [arg, value] = arg.split(/=/)
// skip single letter unknown or '--' options... // skip single letter unknown or '--' options...
@ -1154,15 +1156,12 @@ object.Constructor('Parser', {
// dynamic or error... // dynamic or error...
|| parsed.handler(dfl)[1] || parsed.handler(dfl)[1]
// no handler found and '-*' or '@*' not defined... // no handler found and '-*' or '@*' not defined...
// XXX if nether the whole arg nor it split are found
// we need to push the original to unhandled...
// ...or is setting .splitOptions to false enough???
if(handler == null){ 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)
unhandled.push(arg) unhandled.push(arg)
continue } continue }
//throw module.ParserError(
// `Unknown ${ type == 'opt' ? 'option' : 'command:' } $ARG`,
// arg) }
// mark/unmark handlers... // mark/unmark handlers...
values.delete(handler) values.delete(handler)

View File

@ -18,26 +18,38 @@ var argv = require('../argv')
// ...this can be implemented as a special method/command // ...this can be implemented as a special method/command
// something like .next(..) or .handleRest(..) // something like .next(..) or .handleRest(..)
// - .chain(<parser>) // - .chain(<parser>)
// // XXX might be a good idea to flip this around and instead of
// chaining after do a pre-parse....
var parser = var parser =
exports.parser = exports.parser =
argv.Parser({ argv.Parser({
'-x': {
handler: function(){
console.log('### high priority option') }},
// setup...
// XXX can we go without this??? // XXX can we go without this???
splitOptions: false, splitOptions: false,
// pass help through to the chained parser...
'-help': undefined, '-help': undefined,
// let all the unknown options pass through...
'-*': undefined, '-*': undefined,
}) })
// XXX this works but we still need: // XXX this works but we still need:
// - threading back the results // - threading back the results
// - -help
// XXX would also be interesting to be able to route to specific // XXX would also be interesting to be able to route to specific
// chained parsers... // chained parsers...
.then(argv.Parser({ .then(argv.Parser({
'-moo': { // used for documentation...
handler: function(){ //
console.log('MOO!!!') }}, // 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... // run the parser...