Closed alejandrox1 closed 5 years ago
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: alejandrox1
To complete the pull request process, please assign mtaufen
You can assign the PR to them by writing /assign @mtaufen
in a comment when ready.
The full list of commands accepted by this bot can be found here.
Hi all,wanted to propose this one. So currently people can create their custom flags and register these as
flag.Var(SOMEVal{Val: value})
Within legacyflag, this would create a VarValue
.
The problem is that there is no way of getting the value of the registered flag from the VarValue
struct afterwards which is an essential part of the override pattern that was proposed in https://github.com/kubernetes/kubernetes/pull/73494/files#diff-3c02581ed8bf668707aaade4978f7281R55 .
I have an example of how this could work in https://github.com/kubernetes/kubernetes/pull/79916/files#diff-cf93bbed37202b7d58b5841f07ddd89fR208
I would love any feedback, comments, criticisms you all may have :smiley:
/assign @mtaufen
I want to avoid interface{}
so we maintain type-safety. This was the reason for Apply
just taking a func()
as an argument - it forces you to use a closure to capture the value, which is type-safe.
I think you're right that it's not entirely clear how to use Apply in this case. The following example is roughly what I was thinking:
func AddFlags() (apply func(c *config.Config)) {
var scratch *SomeVal
val := fs.Var(scratch, "someval", "")
afn := func(c *config.Config) {
val.Apply(func(){
c.someval = scratch
})
}
return afn
}
sorry for the delay on this but thank you for your comments! This makes sense :+1: /close
@alejandrox1: Closed this PR.
This method will enable to user to access the value for the registered Flag in the VarValue FlagSet.
Signed-off-by: alejandrox1 alarcj137@gmail.com