summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authors <[email protected]>2025-11-04 13:29:38 -0500
committers <[email protected]>2025-11-04 13:29:38 -0500
commit307f133527fe0c0c95a2fce7a261b1fe4d781a7c (patch)
tree7b73bfe31af7785e93a9b259c0aaca384461854e
parent4486b6659640102dd542fea007f4c33ac02511ff (diff)
downloaddborg-307f133527fe0c0c95a2fce7a261b1fe4d781a7c.tar.gz
dborg-307f133527fe0c0c95a2fce7a261b1fe4d781a7c.zip
refactor: replace auto-update feature with manual update command
-rw-r--r--AUTOUPDATE.md92
-rw-r--r--cmd/update.go33
2 files changed, 33 insertions, 92 deletions
diff --git a/AUTOUPDATE.md b/AUTOUPDATE.md
deleted file mode 100644
index 4c72519..0000000
--- a/AUTOUPDATE.md
+++ /dev/null
@@ -1,92 +0,0 @@
-# Auto-Update Feature
-
-## Overview
-
-The dborg CLI includes an automatic update checker that runs on every program start. It checks the git remote for newer tagged versions and prompts the user to update if available.
-
-## How It Works
-
-1. **Version Check**: On startup, the CLI queries the git remote for the latest tag
-2. **Comparison**: Compares remote version with current version (embedded at build time)
-3. **User Prompt**: If newer version exists, prompts user to update
-4. **Installation**: Runs `go install git.db.org.ai/dborg` to fetch latest version
-5. **Auto-Restart**: Uses `syscall.Exec()` to restart with the new binary seamlessly
-
-## Implementation Details
-
-### Version Embedding
-
-The version is embedded at build time using ldflags:
-
-```bash
-go build -ldflags "-X git.db.org.ai/dborg/internal/utils.Version=v0.1.0"
-```
-
-The Makefile automatically extracts the version from git tags:
-
-```makefile
-VERSION := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0")
-LDFLAGS := -X git.db.org.ai/dborg/internal/utils.Version=$(VERSION)
-```
-
-### Version Check Process
-
-Located in `internal/utils/version.go`:
-
-1. **CheckForUpdates()**: Main entry point called from root command's PersistentPreRunE
-2. **getLatestRemoteTag()**: Queries git remote using `git ls-remote --tags`
-3. **isNewerVersion()**: Simple string comparison for version numbers
-4. **promptAndUpdate()**: Handles user interaction and update process
-5. **restartSelf()**: Restarts the binary using `syscall.Exec()`
-
-### Skip Conditions
-
-Auto-update is skipped when:
-- Running in non-interactive mode (piped output)
-- Version is "dev" (development builds)
-- Git remote query fails (silently continues)
-- No newer version available
-- User declines update
-
-## User Experience
-
-```
-$ dborg npd --firstname John
-
-🔔 A new version of dborg is available: v0.2.0 (current: v0.1.0)
-Would you like to update now? [Y/n]: y
-Updating to v0.2.0...
-✓ Update successful! Restarting...
-
-[Binary automatically restarts and continues with original command]
-```
-
-## Manual Update
-
-Users can always update manually:
-
-```bash
-go install git.db.org.ai/dborg@latest
-```
-
-Or check their current version:
-
-```bash
-dborg version
-```
-
-## Testing
-
-Unit tests cover version comparison logic:
-
-```bash
-go test ./internal/utils -v
-```
-
-## Security Considerations
-
-- Only queries official git remote (git.db.org.ai/dborg)
-- Runs exact command: `go install git.db.org.ai/dborg`
-- No automatic updates without user confirmation
-- Fails safely if update errors occur
-- Preserves original command arguments after restart
diff --git a/cmd/update.go b/cmd/update.go
new file mode 100644
index 0000000..c1aaec3
--- /dev/null
+++ b/cmd/update.go
@@ -0,0 +1,33 @@
+package cmd
+
+import (
+ "fmt"
+ "os"
+ "os/exec"
+
+ "github.com/spf13/cobra"
+)
+
+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`,
+ Run: func(cmd *cobra.Command, args []string) {
+ fmt.Println("Updating dborg...")
+
+ installCmd := exec.Command("go", "install", "git.db.org.ai/dborg")
+ installCmd.Stdout = os.Stdout
+ installCmd.Stderr = os.Stderr
+
+ if err := installCmd.Run(); err != nil {
+ fmt.Fprintf(os.Stderr, "Failed to update dborg: %v\n", err)
+ os.Exit(1)
+ }
+
+ fmt.Println("dborg updated successfully!")
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(updateCmd)
+}