mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 05:27:48 +00:00
add update Instructions
This commit is contained in:
@@ -6,6 +6,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"github.com/fatih/color"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckForUpdate() {
|
func CheckForUpdate() {
|
||||||
@@ -15,7 +20,26 @@ func CheckForUpdate() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if latestVersion != CLI_VERSION {
|
if latestVersion != CLI_VERSION {
|
||||||
PrintWarning(fmt.Sprintf("Please update your CLI. You are running version %s but the latest version is %s", CLI_VERSION, latestVersion))
|
yellow := color.New(color.FgYellow).SprintFunc()
|
||||||
|
blue := color.New(color.FgCyan).SprintFunc()
|
||||||
|
black := color.New(color.FgBlack).SprintFunc()
|
||||||
|
|
||||||
|
msg := fmt.Sprintf("%s %s %s %s",
|
||||||
|
yellow("A new release of infisical is available:"),
|
||||||
|
blue(CLI_VERSION),
|
||||||
|
black("->"),
|
||||||
|
blue(latestVersion),
|
||||||
|
)
|
||||||
|
|
||||||
|
fmt.Fprintln(os.Stderr, msg)
|
||||||
|
|
||||||
|
updateInstructions := GetUpdateInstructions()
|
||||||
|
|
||||||
|
if updateInstructions != "" {
|
||||||
|
msg = fmt.Sprintf("\n%s\n", GetUpdateInstructions())
|
||||||
|
fmt.Fprintln(os.Stderr, msg)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,7 +50,7 @@ func getLatestTag(repoOwner string, repoName string) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
return "", errors.New(fmt.Sprintf("GitHub API returned status code %d", resp.StatusCode))
|
return "", errors.New(fmt.Sprintf("gitHub API returned status code %d", resp.StatusCode))
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
@@ -44,3 +68,53 @@ func getLatestTag(repoOwner string, repoName string) (string, error) {
|
|||||||
|
|
||||||
return tags[0].Name[1:], nil
|
return tags[0].Name[1:], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetUpdateInstructions() string {
|
||||||
|
os := runtime.GOOS
|
||||||
|
switch os {
|
||||||
|
case "darwin":
|
||||||
|
return "To update, run: brew update && brew upgrade infisical"
|
||||||
|
case "windows":
|
||||||
|
return "To update, run: scoop update infisical"
|
||||||
|
case "linux":
|
||||||
|
pkgManager := getLinuxPackageManager()
|
||||||
|
switch pkgManager {
|
||||||
|
case "apt-get":
|
||||||
|
return "To update, run: sudo apt-get update && sudo apt-get install infisical"
|
||||||
|
case "yum":
|
||||||
|
return "To update, run: sudo yum update infisical"
|
||||||
|
case "apk":
|
||||||
|
return "To update, run: sudo apk update && sudo apk upgrade infisical"
|
||||||
|
case "yay":
|
||||||
|
return "To update, run: yay -Syu infisical"
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getLinuxPackageManager() string {
|
||||||
|
cmd := exec.Command("apt-get", "--version")
|
||||||
|
if err := cmd.Run(); err == nil {
|
||||||
|
return "apt-get"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command("yum", "--version")
|
||||||
|
if err := cmd.Run(); err == nil {
|
||||||
|
return "yum"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command("yay", "--version")
|
||||||
|
if err := cmd.Run(); err == nil {
|
||||||
|
return "yay"
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = exec.Command("apk", "--version")
|
||||||
|
if err := cmd.Run(); err == nil {
|
||||||
|
return "apk"
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user