checkForUpdate verifies if the CLI is running the latest version. If the client is out of date, the function returns upgrade instructions.
(c *cli.CLI)
| 50 | // checkForUpdate verifies if the CLI is running the latest version. |
| 51 | // If the client is out of date, the function returns upgrade instructions. |
| 52 | func checkForUpdate(c *cli.CLI) (string, error) { |
| 53 | |
| 54 | ok, err := c.IsUpToDate() |
| 55 | if err != nil { |
| 56 | return "", err |
| 57 | } |
| 58 | |
| 59 | if ok { |
| 60 | return "Your CLI version is up to date.", nil |
| 61 | } |
| 62 | |
| 63 | // Anything but ok is out of date. |
| 64 | msg := fmt.Sprintf("A new CLI version is available. Run `exercism upgrade` to update to %s", c.LatestRelease.Version()) |
| 65 | return msg, nil |
| 66 | |
| 67 | } |
| 68 | |
| 69 | func init() { |
| 70 | RootCmd.AddCommand(versionCmd) |