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

import (
"fmt"
"os"

"github.com/spf13/cobra"
)

func NewShowUpgradeInfoCmd() *cobra.Command {
showUpgradeInfo := &cobra.Command{
Use: "show-upgrade-info",
Short: "Show upgrade-info.json into stdout.",
SilenceUsage: true,
Copy link
Member

Choose a reason for hiding this comment

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

Let's not silence usage.
And let's add cobra.NoArgs

RunE: showUpgradeInfoCmd,
}

return showUpgradeInfo
}

func showUpgradeInfoCmd(cmd *cobra.Command) error {
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