From def53790c8057da7d342fb6b166136874dfc69f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Sat, 14 Aug 2021 15:43:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=91=BD=E4=BB=A4=E8=A1=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=A7=A3=E6=9E=90BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- util/cli.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/util/cli.go b/util/cli.go index 8e17e49..905939e 100644 --- a/util/cli.go +++ b/util/cli.go @@ -13,14 +13,17 @@ import "flag" // // Date : 1:54 下午 2021/8/14 func ParseCLIParameter(parameterNameList []string) map[string]string { - cliParameterTable := make(map[string]string) + cliParameterTable := make(map[string]*string) for _, parameterName := range parameterNameList { - val := flag.String(parameterName, "", parameterName) - cliParameterTable[parameterName] = *val + cliParameterTable[parameterName] = flag.String(parameterName, "", parameterName) } // 这里有一个非常中的操作,转换,必须调用该方法 flag.Parse() - return cliParameterTable + formatTable := make(map[string]string) + for k, v := range cliParameterTable { + formatTable[k] = *v + } + return formatTable } // ParseCLIParameterWithDefaultValue 解析命令行参数,并提供可选的默认值 @@ -29,12 +32,15 @@ func ParseCLIParameter(parameterNameList []string) map[string]string { // // Date : 1:55 下午 2021/8/14 func ParseCLIParameterWithDefaultValue(parameterParseTable map[string]string) map[string]string { - cliParameterTable := make(map[string]string) + cliParameterTable := make(map[string]*string) for parameterName, defaultValue := range parameterParseTable { - val := flag.String(parameterName, defaultValue, parameterName) - cliParameterTable[parameterName] = *val + cliParameterTable[parameterName] = flag.String(parameterName, defaultValue, parameterName) } // 这里有一个非常中的操作,转换,必须调用该方法 flag.Parse() - return cliParameterTable + formatTable := make(map[string]string) + for k, v := range cliParameterTable { + formatTable[k] = *v + } + return formatTable }