-
Notifications
You must be signed in to change notification settings - Fork 56
/
selfupdate.go
42 lines (34 loc) · 1.04 KB
/
selfupdate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main
import (
"context"
"errors"
"fmt"
"net/http"
"github.com/go-clix/cli"
"github.com/grafana/grizzly/internal/grizzly"
)
func selfUpdateCmd() *cli.Command {
cmd := &cli.Command{
Use: "self-update",
Short: "Self update Grizzly",
Args: cli.ArgsExact(0),
}
var opts LoggingOpts
cmd.Run = func(cmd *cli.Command, args []string) error {
updater := grizzly.NewSelfUpdater(http.DefaultClient)
newVersion, err := updater.UpdateSelf(context.Background(), Version)
if errors.Is(err, grizzly.ErrNextVersionIsMajorBump) {
return fmt.Errorf("self-update aborted as the next version (%[1]s) is a major bump from the current one (%[2]s). Please update manually: https://github.com/grafana/grizzly/releases/tag/%[1]s", newVersion, Version)
}
if errors.Is(err, grizzly.ErrCurrentVersionIsLatest) {
fmt.Printf("Current version is the latest: %s\n", Version)
return nil
}
if err != nil {
return err
}
fmt.Printf("Successfully updated to version %s\n", newVersion)
return nil
}
return initialiseLogging(cmd, &opts)
}