mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-29 18:50:09 +00:00
minor refactoring...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
0c214bd034
commit
1112e8af94
17
argv.js
17
argv.js
@ -347,11 +347,8 @@ object.Constructor('Parser', {
|
|||||||
optionPrefix: '-',
|
optionPrefix: '-',
|
||||||
commandPrefix: '@',
|
commandPrefix: '@',
|
||||||
|
|
||||||
// NOTE: this and .commandPattern are "input" patterns, i.e. both
|
optionInputPattern: /^--?(.*)$/,
|
||||||
// are used to test strings the user provided and not how the
|
commandInputPattern: /^([a-zA-Z].*)$/,
|
||||||
// commands/potions are named internally...
|
|
||||||
optionPattern: /^--?(.*)$/,
|
|
||||||
commandPattern: /^([a-zA-Z].*)$/,
|
|
||||||
|
|
||||||
|
|
||||||
// instance stuff...
|
// instance stuff...
|
||||||
@ -407,15 +404,15 @@ object.Constructor('Parser', {
|
|||||||
return this.options(this.commandPrefix) },
|
return this.options(this.commandPrefix) },
|
||||||
|
|
||||||
isCommand: function(str){
|
isCommand: function(str){
|
||||||
return this.commandPattern.test(str)
|
return this.commandInputPattern.test(str)
|
||||||
&& (this.commandPrefix + str) in this },
|
&& (this.commandPrefix + str) in this },
|
||||||
|
|
||||||
// NOTE: this ignores options forming alias loops and dead-end
|
// NOTE: this ignores options forming alias loops and dead-end
|
||||||
// options...
|
// options...
|
||||||
getHandler: function(key){
|
getHandler: function(key){
|
||||||
key = this.optionPattern.test(key) ?
|
key = this.optionInputPattern.test(key) ?
|
||||||
key.replace(this.optionPattern, this.optionPrefix+'$1')
|
key.replace(this.optionInputPattern, this.optionPrefix+'$1')
|
||||||
: key.replace(this.commandPattern, this.commandPrefix+'$1')
|
: key.replace(this.commandInputPattern, this.commandPrefix+'$1')
|
||||||
var seen = new Set([key])
|
var seen = new Set([key])
|
||||||
while(key in this
|
while(key in this
|
||||||
&& typeof(this[key]) == typeof('str')){
|
&& typeof(this[key]) == typeof('str')){
|
||||||
@ -617,7 +614,7 @@ object.Constructor('Parser', {
|
|||||||
this.scriptName = rest.shift().split(/[\\\/]/).pop()
|
this.scriptName = rest.shift().split(/[\\\/]/).pop()
|
||||||
}
|
}
|
||||||
|
|
||||||
var opt_pattern = this.optionPattern
|
var opt_pattern = this.optionInputPattern
|
||||||
|
|
||||||
var unhandled = []
|
var unhandled = []
|
||||||
while(argv.length > 0){
|
while(argv.length > 0){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user