bedrocktool/subcommands/update.go

41 lines
924 B
Go
Raw Normal View History

2023-01-29 21:20:13 +00:00
// Package subcommands ...
2022-09-05 21:57:11 +00:00
package subcommands
import (
"context"
"flag"
"github.com/bedrock-tool/bedrocktool/locale"
2022-09-05 21:57:11 +00:00
"github.com/bedrock-tool/bedrocktool/utils"
"github.com/sirupsen/logrus"
)
type UpdateCMD struct{}
func (*UpdateCMD) Name() string { return "update" }
func (*UpdateCMD) Synopsis() string { return locale.Loc("update_synopsis", nil) }
2022-09-05 21:57:11 +00:00
func (c *UpdateCMD) SetFlags(f *flag.FlagSet) {}
func (c *UpdateCMD) Execute(ctx context.Context, ui utils.UI) error {
2022-09-06 07:48:52 +00:00
newVersion, err := utils.Updater.UpdateAvailable()
if err != nil {
return err
2022-09-06 07:48:52 +00:00
}
if newVersion == "" {
logrus.Info(locale.Loc("no_update", nil))
return nil
2022-09-06 07:48:52 +00:00
}
logrus.Infof(locale.Loc("updating", locale.Strmap{"Version": newVersion}))
2022-09-06 07:48:52 +00:00
2022-09-05 21:57:11 +00:00
if err := utils.Updater.Update(); err != nil {
return err
2022-09-05 21:57:11 +00:00
}
2022-09-06 07:48:52 +00:00
logrus.Infof(locale.Loc("updated", nil))
return nil
2022-09-05 21:57:11 +00:00
}
func init() {
utils.RegisterCommand(&UpdateCMD{})
}