Skip to content
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

utils/cobrautil: support pasring lists from env vars and config file #381

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion utils/cobrautil/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func BindAll(cmd *cobra.Command, envPrefix, configFileFlagName string) error {
ok = true
fs.VisitAll(func(f *pflag.Flag) {
if !f.Changed && v.IsSet(f.Name) {
if err := fs.Set(f.Name, fmt.Sprintf("%v", v.Get(f.Name))); err != nil {
s := fmt.Sprintf("%v", v.Get(f.Name))
s = strings.TrimPrefix(s, "[")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it because we don't have access to the anyflag repo right now? I think it could wait a few days (unless it's problematic to fix in anyflag)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After investigation, it turns out that anyflag follows parsing rules of cobra, so we probably don't want to mess with it.
More advanced parsing is usually implemented in a higher layer and later passed to cobra like I've done here.

s = strings.TrimSuffix(s, "]")
s = strings.NewReplacer(", ", ",", " ", ",").Replace(s)
if err := fs.Set(f.Name, s); err != nil {
fmt.Fprintln(cmd.ErrOrStderr(), err.Error())
ok = false
}
Expand Down