Skip to content

Commit 41d8204

Browse files
Let atlas update from v0.4.0 cross the rename to atlas-cli
The v0.4.0 updater looks for atlas_<version>_<os>_<arch>.tar.gz holding a binary named atlas, which v0.5.0 no longer shipped, so atlas update failed. Releases now also carry those archives with the same program named atlas. Run under the old name, the binary renames itself to atlas-cli on the first command a person types; hooks, the memory bridge and the listener leave it.
1 parent 36aafb0 commit 41d8204

5 files changed

Lines changed: 82 additions & 4 deletions

File tree

‎.goreleaser.yaml‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,40 @@ builds:
2525
- darwin_arm64
2626
- darwin_amd64
2727
mod_timestamp: "{{ .CommitTimestamp }}"
28+
# The same program named atlas, for the updater of v0.4.0 and earlier,
29+
# which looks for atlas_<version>_<os>_<arch>.tar.gz holding "atlas". The
30+
# binary renames itself to atlas-cli on its first run.
31+
- id: atlas-legacy
32+
main: ./cmd/atlas-cli
33+
binary: atlas
34+
env:
35+
- CGO_ENABLED=0
36+
flags:
37+
- -trimpath
38+
ldflags:
39+
- -s -w -X main.version={{ .Version }}
40+
targets:
41+
- linux_amd64
42+
- linux_arm64
43+
- darwin_arm64
44+
- darwin_amd64
45+
mod_timestamp: "{{ .CommitTimestamp }}"
2846

2947
archives:
3048
- id: atlas-cli
49+
ids: [atlas-cli]
3150
formats: [tar.gz]
3251
name_template: "atlas-cli_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
3352
files:
3453
- README.md
3554
- LICENSE*
55+
- id: atlas-legacy
56+
ids: [atlas-legacy]
57+
formats: [tar.gz]
58+
name_template: "atlas_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
59+
files:
60+
- README.md
61+
- LICENSE*
3662

3763
checksum:
3864
name_template: checksums.txt

‎README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ The installer verifies the archive's sha256 and puts `atlas-cli` in `~/.local/bi
4747
`atlas-cli update` does the same in place. From source: `make build` (pure Go, no
4848
cgo).
4949

50-
Coming from a release up to v0.4.0, where the command was `atlas`: run the
51-
installer again (it removes the old `atlas`), then `atlas-cli agents add --all`
52-
in each Project to point the agents' hooks at the new name.
50+
Coming from a release up to v0.4.0, where the command was `atlas`: `atlas
51+
update` (or the installer) brings the new version, which renames itself to
52+
`atlas-cli` the first time you run it. Then run `atlas-cli agents add --all` in
53+
each Project to point the agents' hooks at the new name.
5354

5455
To remove it: `atlas-cli uninstall` takes Atlas's hooks and memory entries out
5556
of every Project, stops the listeners, and deletes the CLI's state and binary.

‎cmd/atlas-cli/main.go‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import (
99
"io"
1010
"os"
1111
"os/signal"
12+
"path/filepath"
1213
"syscall"
1314

1415
"github.com/tryatlas/atlas-cli/internal/tui"
16+
"github.com/tryatlas/atlas-cli/internal/update"
1517
)
1618

1719
// version is set at build time with -ldflags "-X main.version=…".
@@ -21,9 +23,36 @@ var version = "dev"
2123
var stdin io.Reader = os.Stdin
2224

2325
func main() {
26+
if exe, err := update.Executable(); err == nil {
27+
renameLegacy(exe, os.Args[1:], os.Stderr)
28+
}
2429
os.Exit(run(os.Args[1:], os.Stdout, os.Stderr))
2530
}
2631

32+
// renameLegacy moves a binary still called atlas (put there by the updater
33+
// of v0.4.0 and earlier) to atlas-cli in the same folder. Agent hooks, the
34+
// memory bridge and the listener run quietly under the old name; the first
35+
// command a person types does the move and says so.
36+
func renameLegacy(exe string, args []string, stderr io.Writer) {
37+
if filepath.Base(exe) != "atlas" {
38+
return
39+
}
40+
if len(args) > 0 && (args[0] == "hooks" || args[0] == "mcp-bridge" || args[0] == "serve" || args[0] == "uninstall") {
41+
return
42+
}
43+
target := filepath.Join(filepath.Dir(exe), "atlas-cli")
44+
if _, err := os.Lstat(target); err == nil {
45+
fmt.Fprintf(stderr, "atlas-cli: the command is now atlas-cli (%s); delete the old %s.\n", target, exe)
46+
return
47+
}
48+
if err := os.Rename(exe, target); err != nil {
49+
fmt.Fprintf(stderr, "atlas-cli: the command is now atlas-cli, but %s could not be renamed: %v\n", exe, err)
50+
return
51+
}
52+
fmt.Fprintf(stderr, "atlas-cli: the command is now atlas-cli; moved %s to %s.\n", exe, target)
53+
fmt.Fprintln(stderr, "atlas-cli: run atlas-cli agents add --all in each Project to point the agents' hooks at it.")
54+
}
55+
2756
// run executes the command tree and returns the process exit code.
2857
func run(args []string, stdout, stderr io.Writer) int {
2958
if interactive() {

‎cmd/atlas-cli/main_test.go‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"errors"
66
"os"
7+
"path/filepath"
78
"slices"
89
"strings"
910
"testing"
@@ -160,3 +161,22 @@ func TestVersion(t *testing.T) {
160161
t.Fatalf("stdout = %q", got)
161162
}
162163
}
164+
165+
func TestRenameLegacy(t *testing.T) {
166+
dir := t.TempDir()
167+
old := filepath.Join(dir, "atlas")
168+
_ = os.WriteFile(old, []byte("bin"), 0o755)
169+
var e bytes.Buffer
170+
renameLegacy(old, []string{"hooks", "claude-code", "stop"}, &e)
171+
if _, err := os.Stat(old); err != nil || e.Len() != 0 {
172+
t.Fatalf("a hook moved the binary: %v %s", err, e.String())
173+
}
174+
renameLegacy(old, []string{"status"}, &e)
175+
if _, err := os.Stat(filepath.Join(dir, "atlas-cli")); err != nil {
176+
t.Fatal("not moved to atlas-cli")
177+
}
178+
if _, err := os.Stat(old); !os.IsNotExist(err) || !strings.Contains(e.String(), "moved") {
179+
t.Fatalf("old binary left: %v %s", err, e.String())
180+
}
181+
renameLegacy(filepath.Join(dir, "atlas-cli"), nil, &e) // already renamed: nothing to do
182+
}

‎docs/RELEASE.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ runner.
1111
GoReleaser (`.goreleaser.yaml`) builds the four archives
1212
`atlas-cli_<version>_<os>_<arch>.tar.gz` (binary plus README),
1313
`checksums.txt` (sha256) and `install.sh`, and opens a **draft** GitHub
14-
release with them.
14+
release with them. It also builds `atlas_<version>_<os>_<arch>.tar.gz`
15+
holding the same program named `atlas`, so the updater of v0.4.0 and
16+
earlier can still update; that binary renames itself to `atlas-cli`.
1517
- The version comes from the tag: GoReleaser sets `main.version` with
1618
`-X main.version={{ .Version }}`, so `atlas-cli --version` prints
1719
`atlas-cli 1.2.3`. Local builds use `git describe` (`make build`).

0 commit comments

Comments
 (0)