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
I have this habit of using cli arguments that immediately populate a struct:
type ServerArguments struct {
Addresses cli.StringSlice `yaml:"address" json:"address"`
ClientConfig grpc.ClientConfigs `yaml:"client-config" json:"client-config"`
}
func (sa *ServerArguments) GetCliFlags(prefix string) []cli.Flag {
cliFlags := []cli.Flag{
altsrc.NewStringSliceFlag(&cli.StringSliceFlag{
Name: prefix + ".address",
Usage: "List of Grpc addresses. Can be given multiple times",
Value: &cli.StringSlice{}, // could also be 'nil'. same problem
Destination: &sa.Addresses,
}),
}
cliFlags = append(cliFlags, sa.ClientConfig.GetCliFlags("client-config")...)
return cliFlags
}
This is very convenient to simply adding these grpc options to other structs. You can see this in the cliFlags = append(cliFlags... line, where I add another sub-struct I reuse in multiple places.
I usually test my configs by having a Makefile target that does something like:
where cliArguments is a set of nested cli.Flags. This all works great for all types I've used so far, EXCEPT the StringSlice.
Is there something I'm not seeing that I should change? Or do I need to provide some yaml-encoder for StringSlice (as mentioned in some google search results I've found)? If so, wouldn't it be better to pull those into the cli.urfave package?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Version: github.com/urfave/cli/v2 v2.24.4
I have this habit of using cli arguments that immediately populate a struct:
This is very convenient to simply adding these grpc options to other structs. You can see this in the
cliFlags = append(cliFlags...
line, where I add another sub-struct I reuse in multiple places.I usually test my configs by having a Makefile target that does something like:
(i.e. read the default, empty, config I generated in step 1, and parsing it). This errors, because the generated yaml config is
Error:
Code to generate the yaml config is something like
where cliArguments is a set of nested cli.Flags. This all works great for all types I've used so far, EXCEPT the StringSlice.
Is there something I'm not seeing that I should change? Or do I need to provide some yaml-encoder for StringSlice (as mentioned in some google search results I've found)? If so, wouldn't it be better to pull those into the cli.urfave package?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions