mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-30 19:20:08 +00:00
minor tweaking...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
9cd4db01cb
commit
71379b0a42
19
argv.js
19
argv.js
@ -295,8 +295,12 @@ module.Parser =
|
|||||||
object.Constructor('Parser', {
|
object.Constructor('Parser', {
|
||||||
// config...
|
// config...
|
||||||
optionPrefix: '-',
|
optionPrefix: '-',
|
||||||
optionPattern: /^--?(.*)$/,
|
|
||||||
commandPrefix: '@',
|
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].*)$/,
|
commandPattern: /^([a-zA-Z].*)$/,
|
||||||
|
|
||||||
initCheck: true,
|
initCheck: true,
|
||||||
@ -358,8 +362,8 @@ object.Constructor('Parser', {
|
|||||||
&& (this.commandPrefix + str) in this },
|
&& (this.commandPrefix + str) in this },
|
||||||
getHandler: function(key){
|
getHandler: function(key){
|
||||||
key = this.optionPattern.test(key) ?
|
key = this.optionPattern.test(key) ?
|
||||||
key.replace(this.optionPattern, '-$1')
|
key.replace(this.optionPattern, this.optionPrefix+'$1')
|
||||||
: key.replace(this.commandPattern, '@$1')
|
: key.replace(this.commandPattern, 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')){
|
||||||
@ -454,6 +458,8 @@ object.Constructor('Parser', {
|
|||||||
|
|
||||||
// XXX should we explicitly exit here or in the runner???
|
// XXX should we explicitly exit here or in the runner???
|
||||||
return module.STOP }},
|
return module.STOP }},
|
||||||
|
// common shorthands...
|
||||||
|
'-v': '-verbose',
|
||||||
|
|
||||||
|
|
||||||
unknownOption: function(_, key){
|
unknownOption: function(_, key){
|
||||||
@ -478,6 +484,13 @@ object.Constructor('Parser', {
|
|||||||
var that = this
|
var that = this
|
||||||
var nested = false
|
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...
|
// nested command handler...
|
||||||
// XXX the condition is a bit too strong...
|
// XXX the condition is a bit too strong...
|
||||||
if(context instanceof Parser){
|
if(context instanceof Parser){
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user