-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cli version check before every command
- Loading branch information
Showing
3 changed files
with
47 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package util | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
func CheckForUpdate() { | ||
latestVersion, err := getLatestTag("infisical", "infisical") | ||
if err != nil { | ||
// do nothing and continue | ||
return | ||
} | ||
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)) | ||
} | ||
} | ||
|
||
func getLatestTag(repoOwner string, repoName string) (string, error) { | ||
url := fmt.Sprintf("https://api.github.com/repos/%s/%s/tags", repoOwner, repoName) | ||
resp, err := http.Get(url) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
body, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var tags []struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
json.Unmarshal(body, &tags) | ||
|
||
return tags[0].Name, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters