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

feat(tools/cosmovisor): Add ShowUpgradeInfoCmd #21932

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions tools/cosmovisor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#16550](https://github.com/cosmos/cosmos-sdk/pull/16550) Add COSMOVISOR_CUSTOM_PREUPGRADE to cosmovisor to execute custom pre-upgrade scripts (separate from daemon `pre-upgrade` command).
* [#16963](https://github.com/cosmos/cosmos-sdk/pull/16963) Add DAEMON_SHUTDOWN_GRACE to send interrupt and wait before sending kill.
* [#15361](https://github.com/cosmos/cosmos-sdk/pull/15361) Add `cosmovisor config` command to display the configuration used by cosmovisor.
* [#21932](https://github.com/cosmos/cosmos-sdk/pull/21932) Add `cosmovisor show-upgrade-info` command to display the upgrade-info.json into stdout.
Copy link
Member

Choose a reason for hiding this comment

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

the changelog should be under unreleased features.


## 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
48 changes: 48 additions & 0 deletions tools/cosmovisor/cmd/cosmovisor/show_upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package main

import (
"fmt"
"os"

"cosmossdk.io/tools/cosmovisor"
"github.com/spf13/cobra"
)

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

return showUpgradeInfo
}

func showUpgradeInfoCmd(cmd *cobra.Command) 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())
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
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
}
Loading