Skip to content

Commit

Permalink
feat(tools/cosmovisor): Add ShowUpgradeInfoCmd (#21932)
Browse files Browse the repository at this point in the history
Co-authored-by: Bastien Rigaud <[email protected]>
  • Loading branch information
Teyz and Bastien Rigaud authored Sep 28, 2024
1 parent 787ee69 commit e82949d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tools/cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#21462](https://github.com/cosmos/cosmos-sdk/pull/21462) Pass `stdin` to binary.

### Features

* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout.

## v1.6.0 - 2024-08-12

## Improvements
Expand Down
1 change: 1 addition & 0 deletions tools/cosmovisor/cmd/cosmovisor/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func NewRootCmd() *cobra.Command {
configCmd,
NewVersionCmd(),
NewAddUpgradeCmd(),
NewShowUpgradeInfoCmd(),
)

rootCmd.PersistentFlags().StringP(cosmovisor.FlagCosmovisorConfig, "c", "", "path to cosmovisor config file")
Expand Down
49 changes: 49 additions & 0 deletions tools/cosmovisor/cmd/cosmovisor/show_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"

"cosmossdk.io/tools/cosmovisor"
)

func NewShowUpgradeInfoCmd() *cobra.Command {
showUpgradeInfo := &cobra.Command{
Use: "show-upgrade-info",
Short: "Show upgrade-info.json into stdout.",
SilenceUsage: false,
Args: cobra.NoArgs,
RunE: showUpgradeInfoCmd,
}

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 e82949d

Please sign in to comment.