Skip to content

Commit

Permalink
revert second bind
Browse files Browse the repository at this point in the history
  • Loading branch information
ocnc2 committed Jul 28, 2024
1 parent 809b7d2 commit 9d89f13
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 46 deletions.
2 changes: 1 addition & 1 deletion mod/cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ require (
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.12 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
Expand Down
45 changes: 0 additions & 45 deletions mod/cli/pkg/config/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/server"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

Expand All @@ -58,15 +57,6 @@ func SetupConfigAndContext(
return nil, err
}
serverCtx.Config = cometConfig

// not really sure why we have to bind this again here
if err = bindCommandLineFlags(
serverCtx.Viper.GetString(flags.FlagHome),
cmd,
serverCtx.Viper,
); err != nil {
return nil, fmt.Errorf("error binding command line flags: %w", err)
}
return serverCtx, nil
}

Expand Down Expand Up @@ -126,41 +116,6 @@ func bindFlags(cmd *cobra.Command, viper *viper.Viper) error {
return nil
}

// bindCommandLineFlags binds the command line flags to the viper instance.
func bindCommandLineFlags(
basename string, cmd *cobra.Command, v *viper.Viper,
) (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("bindFlags failed: %v", r)
}
}()

cmd.Flags().VisitAll(func(f *pflag.Flag) {
// this should be redundant
err = v.BindEnv(f.Name, fmt.Sprintf("%s_%s", basename, strings.ToUpper(
strings.ReplaceAll(f.Name, "-", "_"))))
if err != nil {
panic(err)
}

err = v.BindPFlag(f.Name, f)
if err != nil {
panic(err)
}

if !f.Changed && v.IsSet(f.Name) {
val := v.Get(f.Name)
err = cmd.Flags().Set(f.Name, fmt.Sprintf("%v", val))
if err != nil {
panic(err)
}
}
})

return err
}

// handleConfigs writes a new comet config file and app config file, and
// merges them into the provided viper instance.
func handleConfigs(
Expand Down

0 comments on commit 9d89f13

Please sign in to comment.