minor tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-06-18 18:30:32 +03:00
parent 9cd4db01cb
commit 71379b0a42

19
argv.js
View File

@ -295,8 +295,12 @@ module.Parser =
object.Constructor('Parser', {
// config...
optionPrefix: '-',
optionPattern: /^--?(.*)$/,
commandPrefix: '@',
// NOTE: this and .commandPattern are "input" patterns, i.e. both
// are used to test strings the user provided and not how the
// commands/potions are named internally...
optionPattern: /^--?(.*)$/,
commandPattern: /^([a-zA-Z].*)$/,
initCheck: true,
@ -358,8 +362,8 @@ object.Constructor('Parser', {
&& (this.commandPrefix + str) in this },
getHandler: function(key){
key = this.optionPattern.test(key) ?
key.replace(this.optionPattern, '-$1')
: key.replace(this.commandPattern, '@$1')
key.replace(this.optionPattern, this.optionPrefix+'$1')
: key.replace(this.commandPattern, this.commandPrefix+'$1')
var seen = new Set([key])
while(key in this
&& typeof(this[key]) == typeof('str')){
@ -454,6 +458,8 @@ object.Constructor('Parser', {
// XXX should we explicitly exit here or in the runner???
return module.STOP }},
// common shorthands...
'-v': '-verbose',
unknownOption: function(_, key){
@ -478,6 +484,13 @@ object.Constructor('Parser', {
var that = this
var nested = false
// default argv...
argv = argv == null ?
process.argv.slice()
: argv
// XXX need to normalize argv...
// XXX ...strip out the interpreter if it is given...
// nested command handler...
// XXX the condition is a bit too strong...
if(context instanceof Parser){