Comparing version 3.0.0 to 3.0.1
@@ -80,2 +80,12 @@ import { ActionHandler, ActionList, ActionRequried } from "./Action"; | ||
* 定义动作处理函数 | ||
* 第一个参数, | ||
* - ActionHandler 的参数为 options 或 argv,执行时值将自动注入 | ||
* 第二个参数,可选三种情况 | ||
* - 传入 false:不要求匹配任何参数,当前命令无论任何 options 或 argv 都将执行 | ||
* - 传入 Array:要求匹配 Array 指定的参数,只有匹配到了才执行 | ||
* - 省略:将自动要求按 ActionHandler 的参数进行匹配 | ||
* 返回值, | ||
* - 如果返回 false ,将会阻止后续其他匹配的 ActionHandler 执行 | ||
* @param handler 处理函数 | ||
* @param required 匹配参数,如果指定必须满足才会执行 handler | ||
*/ | ||
@@ -82,0 +92,0 @@ action(handler: ActionHandler, required?: ActionRequried): this; |
@@ -60,2 +60,12 @@ "use strict"; | ||
* 定义动作处理函数 | ||
* 第一个参数, | ||
* - ActionHandler 的参数为 options 或 argv,执行时值将自动注入 | ||
* 第二个参数,可选三种情况 | ||
* - 传入 false:不要求匹配任何参数,当前命令无论任何 options 或 argv 都将执行 | ||
* - 传入 Array:要求匹配 Array 指定的参数,只有匹配到了才执行 | ||
* - 省略:将自动要求按 ActionHandler 的参数进行匹配 | ||
* 返回值, | ||
* - 如果返回 false ,将会阻止后续其他匹配的 ActionHandler 执行 | ||
* @param handler 处理函数 | ||
* @param required 匹配参数,如果指定必须满足才会执行 handler | ||
*/ | ||
@@ -192,3 +202,3 @@ action(handler, required) { | ||
let subCommendName = this.originArgv[1]; | ||
if (util_1.isNull(subCommendName) || | ||
if (util_1.isNullOrUndefined(subCommendName) || | ||
this.commandList.length < 1 || | ||
@@ -211,3 +221,3 @@ Option_1.Option.test(subCommendName)) { | ||
_hasRepeatChar(str) { | ||
if (util_1.isNull(str)) | ||
if (util_1.isNullOrUndefined(str)) | ||
return false; | ||
@@ -227,13 +237,13 @@ let array = str.split(""); | ||
while (++index < len) { | ||
let token = this.tokenList[index]; | ||
const token = this.tokenList[index]; | ||
if (token.type === Token_1.Token.TYPE_OPTION_NAME) { | ||
// 如果是一个 options | ||
let option = this.optionList.get(token.value); | ||
const option = this.optionList.get(token.value); | ||
// 如果「选项」不存在,或限定的 command 不匹配,添加到 errArray | ||
if (util_1.isNull(option)) { | ||
if (util_1.isNullOrUndefined(option)) { | ||
return new Error("Invalid option: " + token.value); | ||
} | ||
// 如果存在,则检查后边紧临的 token 是否符合「正则」这义的规则 | ||
let nextToken = this.tokenList[++index]; | ||
if (util_1.isNull(nextToken) || | ||
const nextToken = this.tokenList[++index]; | ||
if (util_1.isNullOrUndefined(nextToken) || | ||
(nextToken.type === Token_1.Token.TYPE_OPTION_NAME && !option.type.greed) || | ||
@@ -344,3 +354,3 @@ !option.testValue(nextToken.value)) { | ||
if (this.helpHandler) | ||
return this.consoleInstance.log(this.helpHandler); | ||
return this.helpHandler(); | ||
this.emitError(new Error("No processing")); | ||
@@ -352,3 +362,3 @@ } | ||
_strOrFile(str) { | ||
if (util_1.isNull(str)) | ||
if (util_1.isNullOrUndefined(str)) | ||
return str; | ||
@@ -376,3 +386,3 @@ if (str[0] !== "@") | ||
this.option(["-v", "--version"], "switch"); | ||
this.action(this.versionHandler, true); | ||
this.action(this.versionHandler, ["version"]); | ||
return this; | ||
@@ -392,3 +402,3 @@ } | ||
this.option(["-h", "--help"], "switch"); | ||
this.action(this.helpHandler, true); | ||
this.action(this.helpHandler, ["help"]); | ||
return this; | ||
@@ -401,3 +411,3 @@ } | ||
name = Option_1.Option.trim(name); | ||
if (util_1.isNull(name)) | ||
if (util_1.isNullOrUndefined(name)) | ||
return false; | ||
@@ -404,0 +414,0 @@ return this.params.hasOwnProperty(name); |
{ | ||
"name": "cmdline", | ||
"rawName": "cmdline", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "cmdline is a process.argv parser", | ||
@@ -57,2 +57,2 @@ "main": "./dist/index.js", | ||
} | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
30604
1009
0