-
Notifications
You must be signed in to change notification settings - Fork 0
/
upgrade.go
59 lines (46 loc) 路 1.33 KB
/
upgrade.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cmd
import (
"fmt"
"os"
"github.com/go-dawn/cli/cmd/internal"
"github.com/muesli/termenv"
"github.com/spf13/cobra"
)
var upgradeCmd = &cobra.Command{
Use: "upgrade",
Short: "Upgrade Dawn cli if a newer version is available",
RunE: upgradeRunE,
}
var upgraded bool
func upgradeRunE(cmd *cobra.Command, _ []string) error {
cliLatestVersion, err := latestVersion(true)
if err != nil {
return err
}
if version != cliLatestVersion {
upgrade(cmd, cliLatestVersion)
} else {
msg := fmt.Sprintf("Currently Dawn cli is the latest version %s.", cliLatestVersion)
cmd.Println(termenv.String(msg).
Foreground(termenv.ANSIBrightBlue))
}
return nil
}
func upgrade(cmd *cobra.Command, cliLatestVersion string) {
args := []string{"get", "-u"}
if verbose {
args = append(args, "-v")
}
args = append(args, "github.com/go-dawn/cli/dawn")
upgrader := execCommand("go", args...)
upgrader.Env = append(upgrader.Env, os.Environ()...)
upgrader.Env = append(upgrader.Env, "GO111MODULE=off")
scmd := internal.NewSpinnerCmd(upgrader, "Upgrading")
if err := scmd.Run(); err != nil && !skipSpinner {
cmd.Printf("dawn: failed to upgrade: %v", err)
return
}
success := fmt.Sprintf("Done! Dawn cli is now at v%s!", cliLatestVersion)
cmd.Println(termenv.String(success).Foreground(termenv.ANSIBrightGreen))
upgraded = true
}