mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(util) checkArgs speed up: rm while
This commit is contained in:
parent
acfde11f42
commit
5ce9ceb0f3
1 changed files with 18 additions and 16 deletions
34
lib/util.js
34
lib/util.js
|
|
@ -59,23 +59,25 @@
|
|||
return !!isMatch;
|
||||
};
|
||||
|
||||
this.checkArgs = function(argsParam, names) {
|
||||
var error,
|
||||
msg = '',
|
||||
n = names.length,
|
||||
isLength = n === argsParam.length,
|
||||
template = '{{ name }} coud not be empty!';
|
||||
this.checkArgs = function(args, names) {
|
||||
var msg = '',
|
||||
template = '',
|
||||
name = '',
|
||||
|
||||
lenNames = names.length,
|
||||
lenArgs = args.length,
|
||||
lessArgs = lenArgs < lenNames;
|
||||
|
||||
if (!isLength)
|
||||
while (--n)
|
||||
if (argsParam[n] === undefined) {
|
||||
msg = Util.render(template, {
|
||||
name: names[n]
|
||||
});
|
||||
|
||||
error = new Error(msg);
|
||||
throw(error);
|
||||
}
|
||||
if (lessArgs) {
|
||||
template = '{{ name }} coud not be empty!';
|
||||
name = names[lenNames - 1];
|
||||
|
||||
msg = Util.render(template, {
|
||||
name: name
|
||||
});
|
||||
|
||||
throw(Error(msg));
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue