Files
gastown/internal/cmd/crew_maintenance.go
Steve Yegge 9c3cc0255c refactor(cmd): split crew.go into focused modules
Break down 1184-line crew.go into 8 smaller, focused files:
- crew.go: command definitions, flags, init (229 lines)
- crew_helpers.go: shared utilities (235 lines)
- crew_lifecycle.go: remove/refresh/restart (219 lines)
- crew_status.go: status command (154 lines)
- crew_at.go: session attachment (142 lines)
- crew_maintenance.go: rename/pristine (121 lines)
- crew_list.go: list command (89 lines)
- crew_add.go: add command (74 lines)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 00:46:12 -08:00

122 lines
2.9 KiB
Go

package cmd
import (
"encoding/json"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/steveyegge/gastown/internal/crew"
"github.com/steveyegge/gastown/internal/style"
"github.com/steveyegge/gastown/internal/tmux"
)
func runCrewRename(cmd *cobra.Command, args []string) error {
oldName := args[0]
newName := args[1]
crewMgr, r, err := getCrewManager(crewRig)
if err != nil {
return err
}
// Kill any running session for the old name
t := tmux.NewTmux()
oldSessionID := crewSessionName(r.Name, oldName)
if hasSession, _ := t.HasSession(oldSessionID); hasSession {
if err := t.KillSession(oldSessionID); err != nil {
return fmt.Errorf("killing old session: %w", err)
}
fmt.Printf("Killed session %s\n", oldSessionID)
}
// Perform the rename
if err := crewMgr.Rename(oldName, newName); err != nil {
if err == crew.ErrCrewNotFound {
return fmt.Errorf("crew workspace '%s' not found", oldName)
}
if err == crew.ErrCrewExists {
return fmt.Errorf("crew workspace '%s' already exists", newName)
}
return fmt.Errorf("renaming crew workspace: %w", err)
}
fmt.Printf("%s Renamed crew workspace: %s/%s → %s/%s\n",
style.Bold.Render("✓"), r.Name, oldName, r.Name, newName)
fmt.Printf("New session will be: %s\n", style.Dim.Render(crewSessionName(r.Name, newName)))
return nil
}
func runCrewPristine(cmd *cobra.Command, args []string) error {
crewMgr, r, err := getCrewManager(crewRig)
if err != nil {
return err
}
var workers []*crew.CrewWorker
if len(args) > 0 {
// Specific worker
name := args[0]
worker, err := crewMgr.Get(name)
if err != nil {
if err == crew.ErrCrewNotFound {
return fmt.Errorf("crew workspace '%s' not found", name)
}
return fmt.Errorf("getting crew worker: %w", err)
}
workers = []*crew.CrewWorker{worker}
} else {
// All workers
workers, err = crewMgr.List()
if err != nil {
return fmt.Errorf("listing crew workers: %w", err)
}
}
if len(workers) == 0 {
fmt.Println("No crew workspaces found.")
return nil
}
var results []*crew.PristineResult
for _, w := range workers {
result, err := crewMgr.Pristine(w.Name)
if err != nil {
return fmt.Errorf("pristine %s: %w", w.Name, err)
}
results = append(results, result)
}
if crewJSON {
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
return enc.Encode(results)
}
// Text output
for _, result := range results {
fmt.Printf("%s %s/%s\n", style.Bold.Render("→"), r.Name, result.Name)
if result.HadChanges {
fmt.Printf(" %s\n", style.Bold.Render("⚠ Has uncommitted changes"))
}
if result.Pulled {
fmt.Printf(" %s git pull\n", style.Dim.Render("✓"))
} else if result.PullError != "" {
fmt.Printf(" %s git pull: %s\n", style.Bold.Render("✗"), result.PullError)
}
if result.Synced {
fmt.Printf(" %s bd sync\n", style.Dim.Render("✓"))
} else if result.SyncError != "" {
fmt.Printf(" %s bd sync: %s\n", style.Bold.Render("✗"), result.SyncError)
}
}
return nil
}