From 823081459c46eada5cd05143fee3a001ac5b3bfb Mon Sep 17 00:00:00 2001 From: mars315 <57739378+mars315@users.noreply.github.com> Date: Wed, 3 Jan 2024 20:25:11 +0800 Subject: [PATCH] readme --- README-EN.md | 6 +++--- README.md | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/README-EN.md b/README-EN.md index 6dcc755..6a1e7e4 100644 --- a/README-EN.md +++ b/README-EN.md @@ -2,7 +2,7 @@ Combine [viper](https://github.com/spf13/viper) and [cobra](https://github.com/spf13/cobra) to build a command-line tool, binding command-line arguments to a struct and supporting value retrieval from `viper`. -The first tag of the field represents the name of the flag. If no tag is specified, the field name is used as the flag name. +The first tag of the field represents the name of the flag. If no flag name is specified, the field name is used as the flag name. >> FIELD FIELD_TYPE `FLAG:FLAG_NAME,LABEL,OTHER_LABEL:OTHER_VALUE"` * Label: @@ -21,8 +21,8 @@ The first tag of the field represents the name of the flag. If no tag is specifi # WHY Currently, using `github.com/spf13` to build apps and bind command-line arguments is already convenient. `viper` allows specifying parameters from multiple sources, and values can be retrieved using `viper.GetXXXX`. However, it is not convenient enough for me, and I would like to: 1. Specify command-line parameters through a struct using tags and automatically retrieve values from `viper`. - This way, I can define all the parameters in one struct and directly use them without worrying about where the parameters come from. -2. Avoid hardcoding the names of command function parameters throughout the code, such as `viper.GetString("xxx")`. If the parameter name changes, modifying the code would be necessary. + Use it directly after binding, no need to worry about where the parameter value comes from. +2. You can avoid hard-coding command parameter names into various places in the code, such as `viper.GetString("xxx")`. # HOW diff --git a/README.md b/README.md index b654d70..7e4cfee 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # 总览 -结合 [viper](https://github.com/spf13/viper) 和 [cobra](https://github.com/spf13/cobra) 来构建命令行工具,通过一个struct绑定命令行参数,同时支持从`viper`中获取值 -tag的第一个标签为 flag的名字,如果没有指定tag,则使用字段名字作为flag的名字 +结合 [viper](https://github.com/spf13/viper) 和 [cobra](https://github.com/spf13/cobra) 来构建命令行工具,通过一个struct绑定命令行参数,同时支持从`viper`中获取值。 +tag的第一个标签为 flag的名字;如果没有指定,则使用字段名字作为flag的名字。 > FIELD FIELD_TYPE `FLAG:"FLAG_NAME,LABEL,OTHER_LABEL:OTHER_VALUE"` * 标签: @@ -20,10 +20,9 @@ tag的第一个标签为 flag的名字,如果没有指定tag,则使用字段 # 为什么 当前使用 `github.com/spf13` 来构建app以及绑定命令行参数已经很方便,`viper`可以指定参数来自于多个源,在使用时可以用 `viper:GetXXXX`来获取值。 -但是对于我来说还不足够方便,我希望 -1. 通过一个结构体,同过指定标签的方式来指定命令行参数,同时支持自动从`viper`中获取值; -这样就可以在一个结构体中定义所有的参数并且直接使用,而且不用关心参数来自哪里。 -2. 可以避免将命令函的参数名字硬编码到代码的各个地方,比如 `viper.GetString("xxx")`,这样如果参数名字变了,就需要修改代码 +但是还不足够方便,我希望 +1. 通过一个结构体,用标签的方式来指定命令行参数,同时支持自动从`viper`中获取值; 绑定之后直接使用,不用关心参数的值来自哪里。 +2. 可以避免将命令参数名字硬编码到代码的各个地方,比如 `viper.GetString("xxx")` # 怎么做