Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

add cli version check before every command

Maidul Islama73fc6de19b6
diff --git a/cli/packages/cmd/root.go b/cli/packages/cmd/root.go
index 196c20d7d7..93a498860d 100644
--- a/cli/packages/cmd/root.go
+++ b/cli/packages/cmd/root.go
@@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{
Short: "Infisical CLI is used to inject environment variables into any process",
Long: `Infisical is a simple, end-to-end encrypted service that enables teams to sync and manage their environment variables across their development life cycle.`,
CompletionOptions: cobra.CompletionOptions{HiddenDefaultCmd: true},
- Version: "0.2.5",
+ Version: util.CLI_VERSION,
}
// Execute adds all child commands to the root command and sets flags appropriately.
@@ -33,8 +33,9 @@ func init() {
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
rootCmd.PersistentFlags().BoolVarP(&debugLogging, "debug", "d", false, "Enable verbose logging")
rootCmd.PersistentFlags().StringVar(&config.INFISICAL_URL, "domain", util.INFISICAL_DEFAULT_API_URL, "Point the CLI to your own backend [can also set via environment variable name: INFISICAL_API_URL]")
- // rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
- // }
+ rootCmd.PersistentPreRun = func(cmd *cobra.Command, args []string) {
+ util.CheckForUpdate()
+ }
// if config.INFISICAL_URL is set to the default value, check if INFISICAL_URL is set in the environment
// this is used to allow overrides of the default value
diff --git a/cli/packages/util/check-for-update.go b/cli/packages/util/check-for-update.go
new file mode 100644
index 0000000000..bf66f87e46
--- /dev/null
+++ b/cli/packages/util/check-for-update.go
@@ -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
+}
diff --git a/cli/packages/util/constants.go b/cli/packages/util/constants.go
index 1aa98e2a50..0ff5396b0a 100644
--- a/cli/packages/util/constants.go
+++ b/cli/packages/util/constants.go
@@ -11,4 +11,5 @@ const (
KEYRING_SERVICE_NAME = "infisical"
PERSONAL_SECRET_TYPE_NAME = "personal"
SHARED_SECRET_TYPE_NAME = "shared"
+ CLI_VERSION = "v0.2.5"
)