diff --git a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go index 07da3e08894d..aa37fa36d4e7 100644 --- a/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go +++ b/tools/cosmovisor/cmd/cosmovisor/show_upgrade.go @@ -10,40 +10,33 @@ import ( ) func NewShowUpgradeInfoCmd() *cobra.Command { - showUpgradeInfo := &cobra.Command{ + return &cobra.Command{ Use: "show-upgrade-info", - Short: "Show upgrade-info.json into stdout.", + Short: "Display current upgrade-info.json from data directory", SilenceUsage: false, Args: cobra.NoArgs, - RunE: showUpgradeInfoCmd, + RunE: func(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) { + cmd.Printf("No upgrade info found at %s\n", cfg.UpgradeInfoFilePath()) + return nil + } + return fmt.Errorf("failed to read upgrade-info.json: %w", err) + } + + cmd.Println(string(data)) + return nil + }, } - - 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 }