feat(tools/cosmovisor): Add ShowUpgradeInfoCmd (#21932)
Co-authored-by: Bastien Rigaud <bastienrigaud@mbp-de-bastien.home>
This commit is contained in:
parent
787ee6980f
commit
e82949d57d
@ -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
|
||||
|
||||
@ -19,6 +19,7 @@ func NewRootCmd() *cobra.Command {
|
||||
configCmd,
|
||||
NewVersionCmd(),
|
||||
NewAddUpgradeCmd(),
|
||||
NewShowUpgradeInfoCmd(),
|
||||
)
|
||||
|
||||
rootCmd.PersistentFlags().StringP(cosmovisor.FlagCosmovisorConfig, "c", "", "path to cosmovisor config file")
|
||||
|
||||
49
tools/cosmovisor/cmd/cosmovisor/show_upgrade.go
Normal file
49
tools/cosmovisor/cmd/cosmovisor/show_upgrade.go
Normal 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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user