From 33e4afce60fb74e07b8078308688d9d3591f8b80 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Wed, 26 Aug 2020 13:57:46 +0300 Subject: [PATCH] tweaking and notes.... Signed-off-by: Alex A. Naanou --- argv.js | 11 +++++------ examples/chain.js | 26 +++++++++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/argv.js b/argv.js index 2873d0b..1ab1f6f 100644 --- a/argv.js +++ b/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... + // 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){ - // 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) continue } - //throw module.ParserError( - // `Unknown ${ type == 'opt' ? 'option' : 'command:' } $ARG`, - // arg) } // mark/unmark handlers... values.delete(handler) diff --git a/examples/chain.js b/examples/chain.js index cb76922..d17815c 100644 --- a/examples/chain.js +++ b/examples/chain.js @@ -18,26 +18,38 @@ var argv = require('../argv') // ...this can be implemented as a special method/command // something like .next(..) or .handleRest(..) // - .chain() -// +// 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...