diff options
| author | s <[email protected]> | 2025-11-11 15:10:26 -0500 |
|---|---|---|
| committer | s <[email protected]> | 2025-11-11 15:10:26 -0500 |
| commit | a5fc01a03753c9a18ddeaf13610dd99b4b311b80 (patch) | |
| tree | 546e9d1c5aec5c7bdb84689801af45d293ac9015 | |
| parent | 291708e1f826f4ba8a793d8d3d0706fcb3aa9dc0 (diff) | |
| download | dborg-a5fc01a03753c9a18ddeaf13610dd99b4b311b80.tar.gz dborg-a5fc01a03753c9a18ddeaf13610dd99b4b311b80.zip | |
feat: replace @latest with specific version tags for precise updatesv0.8.3
| -rw-r--r-- | cmd/update.go | 34 | ||||
| -rw-r--r-- | internal/utils/version.go | 7 |
2 files changed, 35 insertions, 6 deletions
diff --git a/cmd/update.go b/cmd/update.go index fe1e958..d664bf0 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -4,18 +4,46 @@ import ( "fmt" "os" "os/exec" + "strings" "github.com/spf13/cobra" ) +func getLatestVersion() (string, error) { + cmd := exec.Command("git", "ls-remote", "--tags", "--refs", "--sort=-v:refname", "[email protected]:repos/dborg.git") + output, err := cmd.Output() + if err != nil { + return "", err + } + + lines := strings.Split(strings.TrimSpace(string(output)), "\n") + if len(lines) == 0 { + return "", fmt.Errorf("no tags found") + } + + parts := strings.Split(lines[0], "refs/tags/") + if len(parts) < 2 { + return "", fmt.Errorf("invalid tag format") + } + + return strings.TrimSpace(parts[1]), nil +} + var updateCmd = &cobra.Command{ Use: "update", Short: "Update dborg to the latest version", - Long: `Update dborg by running go install git.db.org.ai/dborg@latest`, + Long: `Update dborg by running go install git.db.org.ai/dborg@<version>`, Run: func(cmd *cobra.Command, args []string) { fmt.Println("Updating dborg...") - installCmd := exec.Command("go", "install", "git.db.org.ai/dborg@latest") + latestVersion, err := getLatestVersion() + if err != nil { + fmt.Fprintf(os.Stderr, "Failed to get latest version: %v\n", err) + os.Exit(1) + } + + installTarget := fmt.Sprintf("git.db.org.ai/dborg@%s", latestVersion) + installCmd := exec.Command("go", "install", installTarget) installCmd.Stdout = os.Stdout installCmd.Stderr = os.Stderr @@ -24,7 +52,7 @@ var updateCmd = &cobra.Command{ os.Exit(1) } - fmt.Println("dborg updated successfully!") + fmt.Printf("dborg updated successfully to %s!\n", latestVersion) }, } diff --git a/internal/utils/version.go b/internal/utils/version.go index 2b52a8b..847aeb6 100644 --- a/internal/utils/version.go +++ b/internal/utils/version.go @@ -103,19 +103,20 @@ func promptAndUpdate(newVersion string) { response = strings.ToLower(strings.TrimSpace(response)) if response != "" && response != "y" && response != "yes" { - fmt.Fprintf(os.Stderr, "Update skipped. Run 'go install git.db.org.ai/dborg@latest' to update manually.\n\n") + fmt.Fprintf(os.Stderr, "Update skipped. Run 'go install git.db.org.ai/dborg@%s' to update manually.\n\n", newVersion) return } fmt.Fprintf(os.Stderr, "Updating to %s...\n", newVersion) - installCmd := exec.Command("go", "install", "git.db.org.ai/dborg@latest") + installTarget := fmt.Sprintf("git.db.org.ai/dborg@%s", newVersion) + installCmd := exec.Command("go", "install", installTarget) installCmd.Stdout = os.Stderr installCmd.Stderr = os.Stderr if err := installCmd.Run(); err != nil { fmt.Fprintf(os.Stderr, "Failed to update: %v\n", err) - fmt.Fprintf(os.Stderr, "Please update manually: go install git.db.org.ai/dborg@latest\n\n") + fmt.Fprintf(os.Stderr, "Please update manually: go install git.db.org.ai/dborg@%s\n\n", newVersion) return } |
