Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加命令行设置配置参数 #6

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jl2005
Copy link

@jl2005 jl2005 commented Jul 6, 2019

通过在flag.Parse() 之前调用 configo.AddFlags() 方法,即可实现将配置文件中的参数添加到flag中,从而可以通过命令行设置配置文件参数。

@jl2005
Copy link
Author

jl2005 commented Jul 6, 2019

@shafreeck 看一下这种实现方式是否可行。

@shafreeck shafreeck self-requested a review July 8, 2019 10:48
example/conf/example.toml Show resolved Hide resolved
example/conf/example.toml Show resolved Hide resolved
flags.go Outdated Show resolved Hide resolved
flags.go Show resolved Hide resolved
configo.go Outdated
@@ -272,6 +272,9 @@ func Unmarshal(data []byte, v interface{}) error {
if err := applyDefault(reflect.ValueOf(v), false); err != nil {
return err
}

// apply flag param
ApplyFlags(v)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉放到这里,或默认启用flag不太合适,比如我只想解析toml,不想使用flag呢?

是不是考虑将Unmarshal, ApplyFlags, ApplyEnvs 当做独立的函数,然后通过更上层的函数合并起来?

flags.go Outdated
./cmd -array="[\"a1\", \"a2\"]"
*/

var flagMap map[string]struct{} = nil
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flagMap 能否省掉? 比如直接查询FlagSet?

@shafreeck
Copy link
Collaborator

最好翻译为英文, 可以寻求下@xuehuaying 的协助

@xuehuaying
Copy link

这个pr需要我帮助吗?

@jl2005
Copy link
Author

jl2005 commented Jul 23, 2019

这个pr需要我帮助吗?

先等确认版本的,确认之后再翻译,谢谢!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants