Skip to content

Commit

Permalink
fix(cosmovisor): fix show-upgrade info command (#22010)
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt authored Oct 1, 2024
1 parent 8833670 commit a0f9693
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions tools/cosmovisor/cmd/cosmovisor/show_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,33 @@ import (
)

func NewShowUpgradeInfoCmd() *cobra.Command {
showUpgradeInfo := &cobra.Command{
return &cobra.Command{
Use: "show-upgrade-info",
Short: "Show upgrade-info.json into stdout.",
Short: "Display current upgrade-info.json from <app> data directory",
SilenceUsage: false,
Args: cobra.NoArgs,
RunE: showUpgradeInfoCmd,
RunE: func(cmd *cobra.Command, args []string) error {
configPath, err := cmd.Flags().GetString(cosmovisor.FlagCosmovisorConfig)
if err != nil {
return fmt.Errorf("failed to get config flag: %w", err)
}

cfg, err := cosmovisor.GetConfigFromFile(configPath)
if err != nil {
return err
}

data, err := os.ReadFile(cfg.UpgradeInfoFilePath())
if err != nil {
if os.IsNotExist(err) {
cmd.Printf("No upgrade info found at %s\n", cfg.UpgradeInfoFilePath())
return nil
}
return fmt.Errorf("failed to read upgrade-info.json: %w", err)
}

cmd.Println(string(data))
return nil
},
}

return showUpgradeInfo
}

func showUpgradeInfoCmd(cmd *cobra.Command, args []string) error {
configPath, err := cmd.Flags().GetString(cosmovisor.FlagCosmovisorConfig)
if err != nil {
return fmt.Errorf("failed to get config flag: %w", err)
}

cfg, err := cosmovisor.GetConfigFromFile(configPath)
if err != nil {
return err
}

data, err := os.ReadFile(cfg.UpgradeInfoFilePath())
if err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("upgrade-info.json not found at %s: %w", args[0], err)
}
return fmt.Errorf("failed to read upgrade-info.json: %w", err)
}

_, err = fmt.Fprintln(cmd.OutOrStdout(), string(data))
if err != nil {
return fmt.Errorf("failed to write output: %w", err)
}

return nil
}

0 comments on commit a0f9693

Please sign in to comment.