You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sadly, I cant find how to implement this simple setup:
sources:=cli.NewValueSourceChain()
app:=&cli.Command{
EnableShellCompletion: true,
UseShortOptionHandling: true,
Before: func(ctx context.Context, cmd*cli.Command) (context.Context, error) {
config:=cmd.String("config")
iflen(config) >0 {
configFile:=fmt.Sprintf("%s.yaml", cmd.String("config"))
if_, err:=os.Stat(configFile); os.IsNotExist(err) {
returnctx, fmt.Errorf("could not load config file: %s", configFile)
}
sources.Append(cli.Files(configFile))
returnctx, nil
}
returnctx, nil
},
OnUsageError: func(ctx context.Context, cmd*cli.Command, errerror, isSubcommandbool) error {
os.Exit(1)
returnerr
},
ShellComplete: func(ctx context.Context, cmd*cli.Command) {
fmt.Fprintf(cmd.Root().Writer, "check\nnotify\nvalidate\n")
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "Load configuration from `FILE`",
},
},
Commands: []*cli.Command{
{
Name: "notify",
Usage: "Notify Telegram about updates",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "token",
Required: true,
Usage: "`TOKEN` of Telegram's bot",
//Sources: altsrc.YAML("notify.telegram-chat", ???), // how to use sources/files from 'Before'?
},
&cli.StringFlag{
Name: "chat",
Required: true,
Usage: "`ID` of Telegram's chat to send updates",
//Sources: altsrc.YAML("notify.telegram-chat", ???), // how to use sources/files from 'Before'?
},
}
Action: notify.Telegram,
},
Setup is quite typical, tbh - provide custom config file and use values from it. But from docs, it looks like it may work only with hardcoded names? Any direction? Ofc, I could hack around to get config's file outside from the cli package, but I feel that could miss something and there is a built-in way to achieve it.
Can anybody point me to what direction should I look?
P.S.: v3 of cli
The text was updated successfully, but these errors were encountered:
@plandem I have a PoC PR which might help resolve your issue. You may have to customize the value source to read the flag value and load files. I have to think more on this.
@plandem I have a PoC PR which might help resolve your issue. You may have to customize the value source to read the flag value and load files. I have to think more on this.
not sure how to use it :( since its PoC, do you need some feedback or what is the next step to make it possible (i mean original topic of discussion)?
Discussed in #2032
Originally posted by plandem December 23, 2024
Hi
Sadly, I cant find how to implement this simple setup:
Setup is quite typical, tbh - provide custom config file and use values from it. But from docs, it looks like it may work only with hardcoded names? Any direction? Ofc, I could hack around to get config's file outside from the
cli
package, but I feel that could miss something and there is a built-in way to achieve it.Can anybody point me to what direction should I look?
P.S.: v3 of cli
The text was updated successfully, but these errors were encountered: