Skip to content

Commit fcb01d1

Browse files
chuongld20claude
andcommitted
chore: simplify Phase 1 code and bump version to v0.1.0
- Extract duplicated SSH+Tailscale unserve pattern into unservePorts() - Replace stringly-typed "already exists" check with ErrAlreadyExists sentinel - Bump version from 0.1.0-dev to 0.1.0 for first public release Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c425018 commit fcb01d1

1 file changed

Lines changed: 21 additions & 29 deletions

File tree

cmd/devbox/main.go

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
)
2323

2424
var (
25-
version = "0.1.0-dev"
25+
version = "0.1.0"
2626
verbose bool
2727
noColor bool
2828
)
@@ -82,6 +82,24 @@ func remoteRunner(sshExec devboxssh.Executor, server string) tailscale.CommandRu
8282
}
8383
}
8484

85+
// unservePorts tears down Tailscale serve entries for all workspace ports.
86+
// Errors are logged as warnings but do not stop the operation.
87+
func unservePorts(ws *workspace.Workspace) {
88+
sshExec, err := devboxssh.New()
89+
if err != nil {
90+
fmt.Fprintf(os.Stderr, "Warning: failed to connect for port cleanup: %v\n", err)
91+
return
92+
}
93+
defer sshExec.Close()
94+
95+
tm := tailscale.NewManager(remoteRunner(sshExec, ws.ServerHost))
96+
for _, port := range ws.Ports {
97+
if err := tm.Unserve(port); err != nil {
98+
fmt.Fprintf(os.Stderr, "Warning: failed to unserve port %d: %v\n", port, err)
99+
}
100+
}
101+
}
102+
85103
func upCmd(wm workspace.Manager) *cobra.Command {
86104
cmd := &cobra.Command{
87105
Use: "up [project]",
@@ -192,20 +210,7 @@ func stopCmd(wm workspace.Manager) *cobra.Command {
192210
return fmt.Errorf("devbox stop: %w", err)
193211
}
194212

195-
sshExec, err := devboxssh.New()
196-
if err != nil {
197-
ui.StopSpinner(spin, false)
198-
return fmt.Errorf("devbox stop: %w", err)
199-
}
200-
defer sshExec.Close()
201-
202-
tm := tailscale.NewManager(remoteRunner(sshExec, ws.ServerHost))
203-
for _, port := range ws.Ports {
204-
if err := tm.Unserve(port); err != nil {
205-
fmt.Fprintf(os.Stderr, "Warning: failed to unserve port %d: %v\n", port, err)
206-
}
207-
}
208-
213+
unservePorts(ws)
209214
ui.StopSpinner(spin, true)
210215
fmt.Printf("Workspace %q stopped\n", name)
211216
return nil
@@ -282,20 +287,7 @@ func destroyCmd(wm workspace.Manager) *cobra.Command {
282287
return fmt.Errorf("devbox destroy: %w", err)
283288
}
284289

285-
sshExec, err := devboxssh.New()
286-
if err != nil {
287-
ui.StopSpinner(spin, false)
288-
return fmt.Errorf("devbox destroy: %w", err)
289-
}
290-
defer sshExec.Close()
291-
292-
tm := tailscale.NewManager(remoteRunner(sshExec, ws.ServerHost))
293-
for _, port := range ws.Ports {
294-
if err := tm.Unserve(port); err != nil {
295-
fmt.Fprintf(os.Stderr, "Warning: failed to unserve port %d: %v\n", port, err)
296-
}
297-
}
298-
290+
unservePorts(ws)
299291
ui.StopSpinner(spin, true)
300292
fmt.Printf("Workspace %q destroyed\n", name)
301293
return nil

0 commit comments

Comments
 (0)