[SSE] Refactoring arguments names
This commit is contained in:
parent
09e95ddf0d
commit
b91dd162bc
|
@ -97,6 +97,7 @@ define([
|
||||||
this._noApply = false;
|
this._noApply = false;
|
||||||
this.args = [];
|
this.args = [];
|
||||||
this.argsNames = [];
|
this.argsNames = [];
|
||||||
|
this.repeatedIdx = 1;
|
||||||
this.repeatedArg = undefined;
|
this.repeatedArg = undefined;
|
||||||
this.helpUrl = undefined;
|
this.helpUrl = undefined;
|
||||||
this.minArgCount = 1;
|
this.minArgCount = 1;
|
||||||
|
@ -191,6 +192,7 @@ define([
|
||||||
|
|
||||||
if (typeof type == 'object') {
|
if (typeof type == 'object') {
|
||||||
this.repeatedArg = type;
|
this.repeatedArg = type;
|
||||||
|
this.fillRepeatedNames();
|
||||||
types = type;
|
types = type;
|
||||||
} else
|
} else
|
||||||
types.push(type);
|
types.push(type);
|
||||||
|
@ -259,16 +261,39 @@ define([
|
||||||
this.argsNames = arr;
|
this.argsNames = arr;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
fillRepeatedNames: function() {
|
||||||
|
if (this.argsNames.length<1) return;
|
||||||
|
if (this.repeatedArg && this.repeatedArg.length>0 && this.argsNames[this.argsNames.length-1]==='...') {
|
||||||
|
var req = this.argsNames.length-1 - this.repeatedArg.length; // required/no-repeated
|
||||||
|
for (var i=0; i<this.repeatedArg.length; i++) {
|
||||||
|
var str = this.argsNames[this.argsNames.length-2-i],
|
||||||
|
ch = str.charAt(str.length-1);
|
||||||
|
if ('123456789'.indexOf(ch)>-1) {
|
||||||
|
this.repeatedIdx = parseInt(ch);
|
||||||
|
this.argsNames[this.argsNames.length-2-i] = str.substring(0, str.length-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
getArgumentName: function(argcount) {
|
getArgumentName: function(argcount) {
|
||||||
var name = '';
|
var name = '',
|
||||||
if (argcount<this.argsNames.length && this.argsNames[argcount]!=='...') {
|
namesLen = this.argsNames.length;
|
||||||
|
if ((!this.repeatedArg || this.repeatedArg.length<1) && argcount<namesLen && this.argsNames[argcount]!=='...') // no repeated args
|
||||||
name = this.argsNames[argcount];
|
name = this.argsNames[argcount];
|
||||||
} else if (this.argsNames[this.argsNames.length-1]==='...') {
|
else if (this.repeatedArg && this.repeatedArg.length>0 && this.argsNames[namesLen-1]==='...') {
|
||||||
var req = this.argsNames.length-1 - this.repeatedArg.length; // required
|
var repeatedLen = this.repeatedArg.length;
|
||||||
var idx = this.repeatedArg.length - (argcount - req)%this.repeatedArg.length;
|
var req = namesLen-1 - repeatedLen; // required/no-repeated
|
||||||
name = this.argsNames[this.argsNames.length-1-idx];
|
if (argcount<req) // get required args as is
|
||||||
|
name = this.argsNames[argcount];
|
||||||
|
else {
|
||||||
|
var idx = repeatedLen - (argcount - req)%repeatedLen,
|
||||||
|
num = Math.floor((argcount - req)/repeatedLen) + this.repeatedIdx;
|
||||||
|
name = this.argsNames[namesLen-1-idx] + num;
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
name = this.textArgument + (this.maxArgCount>1 ? (' ' + (argcount+1)) : '');
|
name = this.textArgument + (this.maxArgCount>1 ? (' ' + (argcount+1)) : '');
|
||||||
|
|
||||||
return name;
|
return name;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue