feat(tools/cosmovisor): Add ShowUpgradeInfoCmd (#21932)

Co-authored-by: Bastien Rigaud <bastienrigaud@mbp-de-bastien.home>
This commit is contained in:
Bastien R. 2024-09-28 21:23:11 +02:00 committed by GitHub
parent 787ee6980f
commit e82949d57d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 54 additions and 0 deletions

View File

@ -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

View File

@ -19,6 +19,7 @@ func NewRootCmd() *cobra.Command {
configCmd,
NewVersionCmd(),
NewAddUpgradeCmd(),
NewShowUpgradeInfoCmd(),
)
rootCmd.PersistentFlags().StringP(cosmovisor.FlagCosmovisorConfig, "c", "", "path to cosmovisor config file")

View File

@ -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
}