Skip to content

Commit

Permalink
readme
Browse files Browse the repository at this point in the history
  • Loading branch information
mars315 committed Jan 3, 2024
1 parent 87940a7 commit 8230814
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -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"`
* 标签:
Expand All @@ -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")`

# 怎么做

Expand Down

0 comments on commit 8230814

Please sign in to comment.