-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed as not planned
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/questionsomeone asking a questionsomeone asking a questionstatus/triagemaintainers still need to look into thismaintainers still need to look into thisstatus/waiting-for-responseWaiting for response from original requesterWaiting for response from original requester
Milestone
Description
How to use a YAML config file to set flags? I've read the docs and tried a couple of things; then waited a month and read them again but, nothing seems to work.
I'm using v2.3.0.
package cli
var Flags []cli.Flag
func init() {
Flags = []cli.Flag{
altsrc.NewStringFlag(
&cli.StringFlag{
Required: true,
Name: "foo",
}
)
}
}package main
// In main()
app := &cli.App{
Name: "tester",
Before: altsrc.InitInputSourceWithContext(cmd.Flags,
func(context *cli.Context) (altsrc.InputSourceContext, error) {
return altsrc.NewYamlSourceFromFile(".myconfig")
}
)
}But every time I run it I get an error because foo is required and not set.
I have also tried what sounds like a more verbose version of the above:
app := &cli.App{
Name: "sdt",
Before: func (c *cli.Context) error {
src, err := altsrc.NewYamlSourceFromFile(".myconfig")
if err != nil {
return err
}
fmt.Printf("%+v\n", src)
err = altsrc.ApplyInputSourceValues(c, src, cmd.Flags)
if err != nil {
return err
}
return nil
},
}The config is printed and everything is there but the flag is never assigned.
I thought it may be related to #1086 but this appears to be fixed in v2.3.0. Help!
Metadata
Metadata
Assignees
Labels
area/v2relates to / is being considered for v2relates to / is being considered for v2kind/questionsomeone asking a questionsomeone asking a questionstatus/triagemaintainers still need to look into thismaintainers still need to look into thisstatus/waiting-for-responseWaiting for response from original requesterWaiting for response from original requester