mirror of
https://github.com/flynx/argv.js.git
synced 2025-10-28 18:30:07 +00:00
now placeholder values are inherited from .parent + tweaked option prioorities + now bool type supports 'true'/'false' keywords...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
d2c16d862d
commit
bd39dcfb5d
33
argv.js
33
argv.js
@ -292,7 +292,12 @@ object.Constructor('Parser', {
|
|||||||
// definition.
|
// definition.
|
||||||
typeHandlers: {
|
typeHandlers: {
|
||||||
string: function(v){ return v.toString() },
|
string: function(v){ return v.toString() },
|
||||||
bool: function(v){ return !!v },
|
bool: function(v){
|
||||||
|
return v == 'true' ?
|
||||||
|
true
|
||||||
|
: v == 'false' ?
|
||||||
|
false
|
||||||
|
: !!v },
|
||||||
int: parseInt,
|
int: parseInt,
|
||||||
float: parseFloat,
|
float: parseFloat,
|
||||||
number: function(v){ return new Number(v) },
|
number: function(v){ return new Number(v) },
|
||||||
@ -641,24 +646,28 @@ object.Constructor('Parser', {
|
|||||||
[a +'\t'.repeat(opts_width - Math.floor((a.strip || a).length/8))+ prefix + b]
|
[a +'\t'.repeat(opts_width - Math.floor((a.strip || a).length/8))+ prefix + b]
|
||||||
: [a, '\t'.repeat(opts_width)+ prefix + b])
|
: [a, '\t'.repeat(opts_width)+ prefix + b])
|
||||||
: [a] },
|
: [a] },
|
||||||
|
// NOTE: if var value is not defined here we'll try and get it from
|
||||||
|
// parent...
|
||||||
expandTextVars: function(text){
|
expandTextVars: function(text){
|
||||||
var that = this
|
var that = this
|
||||||
var get = function(attr, dfl){
|
var get = function(o, attr, dfl){
|
||||||
return (typeof(that[attr]) == 'function' ?
|
return (typeof(o[attr]) == 'function' ?
|
||||||
that[attr]()
|
o[attr]()
|
||||||
: that[attr])
|
: o[attr])
|
||||||
|| dfl }
|
|| (o.parent ?
|
||||||
|
get(o.parent, attr, dfl)
|
||||||
|
: dfl )}
|
||||||
return text
|
return text
|
||||||
.replace(/\$AUTHOR/g, get('author', 'Author'))
|
.replace(/\$AUTHOR/g, get(that, 'author', 'Author'))
|
||||||
.replace(/\$LICENSE/g, get('license', '-'))
|
.replace(/\$LICENSE/g, get(that, 'license', '-'))
|
||||||
.replace(/\$VERSION/g, get('version', '0.0.0'))
|
.replace(/\$VERSION/g, get(that, 'version', '0.0.0'))
|
||||||
.replace(/\$SCRIPTNAME/g, this.scriptName) },
|
.replace(/\$SCRIPTNAME/g, this.scriptName) },
|
||||||
|
|
||||||
// NOTE: this will set .quiet to false...
|
// NOTE: this will set .quiet to false...
|
||||||
'-h': '-help',
|
'-h': '-help',
|
||||||
'-help': {
|
'-help': {
|
||||||
doc: 'print this message and exit',
|
doc: 'print this message and exit',
|
||||||
priority: 99,
|
priority: 90,
|
||||||
handler: function(argv, key, value){
|
handler: function(argv, key, value){
|
||||||
var that = this
|
var that = this
|
||||||
var sep = this.helpArgumentSeparator || ', '
|
var sep = this.helpArgumentSeparator || ', '
|
||||||
@ -825,7 +834,7 @@ object.Constructor('Parser', {
|
|||||||
'-v': '-version',
|
'-v': '-version',
|
||||||
'-version': {
|
'-version': {
|
||||||
doc: 'show $SCRIPTNAME version and exit',
|
doc: 'show $SCRIPTNAME version and exit',
|
||||||
priority: 99,
|
priority: 80,
|
||||||
handler: function(){
|
handler: function(){
|
||||||
this.quiet = false
|
this.quiet = false
|
||||||
this.print((typeof(this.version) == 'function' ?
|
this.print((typeof(this.version) == 'function' ?
|
||||||
@ -841,7 +850,7 @@ object.Constructor('Parser', {
|
|||||||
|
|
||||||
'-q': '-quiet',
|
'-q': '-quiet',
|
||||||
'-quiet': {
|
'-quiet': {
|
||||||
priority: 99,
|
priority: 70,
|
||||||
doc: 'quiet mode',
|
doc: 'quiet mode',
|
||||||
default: true, },
|
default: true, },
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user