-
-
Notifications
You must be signed in to change notification settings - Fork 361
/
Copy pathupgrade.go
58 lines (46 loc) · 1.23 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
package cmd
import (
"fmt"
"github.com/exercism/cli/cli"
"github.com/spf13/cobra"
)
// upgradeCmd downloads and installs the most recent version of the CLI.
var upgradeCmd = &cobra.Command{
Use: "upgrade",
Aliases: []string{"u"},
Short: "Upgrade to the latest version of the CLI.",
Long: `Upgrade to the latest version of the CLI.
This finds and downloads the latest release, if you don't
already have it.
On Windows the old CLI will be left on disk, marked as hidden.
The next time you upgrade, the hidden file will be overwritten.
You can always delete this file.
`,
RunE: func(cmd *cobra.Command, args []string) error {
c := cli.New(Version)
err := updateCLI(c)
if err != nil {
return fmt.Errorf(`
We were not able to upgrade the cli because we encountered an error:
%s
Please check the FAQ for solutions to common upgrading issues.
https://exercism.org/faqs`, err)
}
return nil
},
}
// updateCLI updates CLI to the latest available version, if it is out of date.
func updateCLI(c cli.Updater) error {
ok, err := c.IsUpToDate()
if err != nil {
return err
}
if ok {
fmt.Fprintln(Out, "Your CLI version is up to date.")
return nil
}
return c.Upgrade()
}
func init() {
RootCmd.AddCommand(upgradeCmd)
}