Skip to content

Commit

Permalink
POS-17:Add Heimdall flags for configuration (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemanja0x authored Dec 23, 2021
1 parent 9d918a9 commit cd3806d
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 54 deletions.
3 changes: 3 additions & 0 deletions bridge/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ func main() {
var logger = helper.Logger.With("module", "bridge/cmd/")
rootCmd := cmd.BridgeCommands(viper.GetViper(), logger, "bridge-main")

// add heimdall flags
helper.DecorateWithHeimdallFlags(rootCmd, viper.GetViper(), logger, "bridge-main")

if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
9 changes: 0 additions & 9 deletions bridge/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ func DecorateWithBridgeRootFlags(cmd *cobra.Command, v *viper.Viper, loggerInsta
loggerInstance.Error(fmt.Sprintf("%v | BindPFlag | %v", caller, helper.HomeFlag), "Error", err)
}

cmd.PersistentFlags().String(
helper.WithHeimdallConfigFlag,
"",
"Heimdall config file path (default <home>/config/heimdall-config.json)",
)
if err := v.BindPFlag(helper.WithHeimdallConfigFlag, cmd.PersistentFlags().Lookup(helper.WithHeimdallConfigFlag)); err != nil {
loggerInstance.Error(fmt.Sprintf("%v | BindPFlag | %v", caller, helper.WithHeimdallConfigFlag), "Error", err)
}

// bridge storage db
cmd.PersistentFlags().String(
bridgeDBFlag,
Expand Down
9 changes: 2 additions & 7 deletions cmd/heimdallcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ var (
func initTendermintViperConfig(cmd *cobra.Command) {
tendermintNode, _ := cmd.Flags().GetString(helper.TendermintNodeFlag)
homeValue, _ := cmd.Flags().GetString(helper.HomeFlag)
withHeimdallConfigValue, _ := cmd.Flags().GetString(helper.WithHeimdallConfigFlag)

// set to viper
viper.Set(helper.TendermintNodeFlag, tendermintNode)
viper.Set(helper.HomeFlag, homeValue)
viper.Set(helper.WithHeimdallConfigFlag, withHeimdallConfigValue)

// start heimdall config
helper.InitHeimdallConfig("")
Expand All @@ -89,6 +87,8 @@ func main() {
// chain id
rootCmd.PersistentFlags().String(client.FlagChainID, "", "Chain ID of tendermint node")

helper.DecorateWithHeimdallFlags(rootCmd, viper.GetViper(), logger, "main")

// add query/post commands (custom to binary)
rootCmd.AddCommand(
rpc.StatusCommand(),
Expand All @@ -111,11 +111,6 @@ func main() {
ApproveCmd(cliCtx),
)

// bind with-heimdall-config config with root cmd
if err := viper.BindPFlag(helper.WithHeimdallConfigFlag, rootCmd.Flags().Lookup(helper.WithHeimdallConfigFlag)); err != nil {
logger.Error("main | BindPFlag | helper.WithHeimdallConfigFlag", "Error", err)
}

// prepare and add flags
executor := cli.PrepareMainCmd(rootCmd, "HD", os.ExpandEnv("$HOME/.heimdalld"))
err := executor.Execute()
Expand Down
24 changes: 3 additions & 21 deletions cmd/heimdalld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,32 +111,14 @@ func main() {
PersistentPreRunE: server.PersistentPreRunEFn(ctx),
}

// adding heimdall configuration flags to root command
helper.DecorateWithHeimdallFlags(rootCmd, viper.GetViper(), logger, "main")

tendermintCmd := &cobra.Command{
Use: "tendermint",
Short: "Tendermint subcommands",
}

// add new persistent flag for heimdall-config
rootCmd.PersistentFlags().String(
helper.WithHeimdallConfigFlag,
"",
"Heimdall config file path (default <home>/config/heimdall-config.json)",
)

rootCmd.PersistentFlags().String(
helper.ChainFlag,
"",
fmt.Sprintf("Set one of the chains: [%s]", strings.Join(helper.GetValidChains(), ",")),
)

// bind with-heimdall-config config and chain flag with root cmd
if err := viper.BindPFlag(helper.WithHeimdallConfigFlag, rootCmd.PersistentFlags().Lookup(helper.WithHeimdallConfigFlag)); err != nil {
logger.Error("main | BindPFlag | helper.WithHeimdallConfigFlag", "Error", err)
}
if err := viper.BindPFlag(helper.ChainFlag, rootCmd.PersistentFlags().Lookup(helper.ChainFlag)); err != nil {
logger.Error("main | BindPFlag | helper.ChainFlag", "Error", err)
}

rootCmd.AddCommand(heimdallStart(shutdownCtx, ctx, newApp, cdc)) // New Heimdall start command

tendermintCmd.AddCommand(
Expand Down
Loading

0 comments on commit cd3806d

Please sign in to comment.