Skip to content

Commit 1952e73

Browse files
authored
fix: version read path (#89)
* fix: version read path
1 parent 80aa43a commit 1952e73

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

cmd/update.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package cmd
22

33
import (
4-
"codacy/cli-v2/config"
54
"fmt"
65
"os"
76
"path/filepath"
7+
"runtime"
88

99
"github.com/spf13/cobra"
1010
"gopkg.in/yaml.v3"
@@ -15,13 +15,34 @@ var updateCmd = &cobra.Command{
1515
Short: "Update to the latest version",
1616
Long: ``,
1717
Run: func(cmd *cobra.Command, args []string) {
18+
// Get the cache directory based on OS or environment variable
19+
var cacheDir string
20+
envDir := os.Getenv("CODACY_CLI_V2_TMP_FOLDER")
21+
if envDir != "" {
22+
cacheDir = envDir
23+
} else {
24+
homePath, err := os.UserHomeDir()
25+
if err != nil {
26+
fmt.Printf("Failed to get home directory: %v\n", err)
27+
os.Exit(1)
28+
}
29+
switch runtime.GOOS {
30+
case "linux":
31+
cacheDir = filepath.Join(homePath, ".cache", "codacy", "codacy-cli-v2")
32+
case "darwin":
33+
cacheDir = filepath.Join(homePath, "Library", "Caches", "Codacy", "codacy-cli-v2")
34+
default:
35+
cacheDir = ".codacy-cli-v2"
36+
}
37+
}
38+
1839
// Read version from yaml
19-
versionFile := filepath.Join(config.Config.CodacyDirectory(), "version.yaml")
40+
versionFile := filepath.Join(cacheDir, "version.yaml")
2041
versionData, err := os.ReadFile(versionFile)
2142
if err != nil {
2243
if os.IsNotExist(err) {
2344
fmt.Println("Could not read version file. Make sure you have the latest version of the script at:")
24-
fmt.Println("https://github.com/codacy/codacy-cli-v2/blob/main/README.md#download t")
45+
fmt.Println("https://github.com/codacy/codacy-cli-v2/blob/main/README.md#download")
2546
} else {
2647
fmt.Printf("Failed to read version.yaml: %v\n", err)
2748
}

codacy-cli.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,13 @@ download_cli() {
9999

100100
download "$url" "$bin_folder"
101101
tar xzfv "${bin_folder}/${remote_file}" -C "${bin_folder}"
102-
else
103-
echo "✓ Using cached CLI version $version"
104102
fi
105103
}
106104

107105
# Warn if CODACY_CLI_V2_VERSION is set and update is requested
108106
if [ -n "$CODACY_CLI_V2_VERSION" ] && [ "$1" = "update" ]; then
109107
echo "⚠️ Warning: Performing update with forced version $CODACY_CLI_V2_VERSION"
110-
echo " This might prevent updating to the latest version"
108+
echo " Unset CODACY_CLI_V2_VERSION to use the latest version"
111109
fi
112110

113111
# Ensure version.yaml exists and is up to date

0 commit comments

Comments
 (0)