-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
BUG: Useing altsrc when flag has multiple names #519
Comments
It does feel like |
I agree with @jszwedko, it seems like a bug, this seems like we should use name instead of f.Name. I don't think I really had much testing around the scenario where there are multiple of one flag. Are you seeing bad behavior when the short flag and long flag are used in combination @dixonwille ? |
I am but replacing that single variable didn't seem to work. |
@dixonwille perhaps you can give a pointer to your actual code and tests? I'm not exactly sure of the problem. My approach would be to add the test scenario I want to work and evaluate its behavior, sorry if I'm repeating myself from above. I don't have a ton of time to attempt this work myself right now but could review your code if that helps? |
Code is on internal Enterprise Github. Here is the snippet though. altsrc.NewStringFlag(cli.StringFlag{
Name: "user",
Usage: "The SQL `USERNAME`",
}), I would like to make the name |
So to clarify what you want to do is something like this? Based on the example above you would need to change it to this? altsrc.NewStringFlag(cli.StringFlag{
Name: "user, u",
Usage: "The SQL USERNAME",
}) Then when you put a command line like this it doesn't work? cmd do-something --u chris --user dixon |
Well passing it through as flags it works. It's loading from the file into the flags that is not working. If I add |
In the yaml file do you want to be able to value by both names, u and user? This may not compile but can you tweak the function below to something like this? func (f *StringFlag) ApplyInputSourceValue(context *cli.Context, isc InputSourceContext) error {
if f.set != nil {
if !(context.IsSet(f.Name) || isEnvVarSet(f.EnvVar)) {
if value != "" {
eachName(f.Name, func(name string) {
value, err := isc.String(name)
if err != nil {
return err
}
f.set.Set(f.Name, value)
})
}
}
}
return nil
} So I think what its doing for yaml anyway is its trying to do a lookup for "user, u" and not user. Then it doesn't find it and no value is returned. |
That is what I would expect to happen anyways. But yes that is what I think is going on. When I have time I will try a few things but starting there. |
Hiya! There's a known issue with the current implementation of the CLI, where altsrc is generally clunky and poorly documented. My current idea is that I'm going to move all of the |
In this code, you are never using the eachName's functions variable
name
. This caught my attention then realized thatf.Name
could be equal touser,u
which you will never be set in context. So then I realized that the eachName should wrap everything inside theif f.set
. then changing allf.Name
inside toname
. Also seems likef.GenericFlag.Name
should also be renamed toname
.The text was updated successfully, but these errors were encountered: