fix: code review fixes from gt-2tp and gt-y0t
- Replace custom contains() with strings.Contains in init.go - Make session stop --force flag actually work - Update session.Manager.Stop() to accept force parameter 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/steveyegge/gastown/internal/git"
|
||||
@@ -106,8 +107,7 @@ func updateGitExclude(repoPath string) error {
|
||||
}
|
||||
|
||||
// Check if already has Gas Town section
|
||||
contentStr := string(content)
|
||||
if len(content) > 0 && contains(contentStr, "Gas Town") {
|
||||
if strings.Contains(string(content), "Gas Town") {
|
||||
return nil // Already configured
|
||||
}
|
||||
|
||||
@@ -126,16 +126,3 @@ func updateGitExclude(repoPath string) error {
|
||||
// Write back
|
||||
return os.WriteFile(excludePath, append(content, []byte(additions)...), 0644)
|
||||
}
|
||||
|
||||
func contains(s, substr string) bool {
|
||||
return len(s) >= len(substr) && (s == substr || len(s) > 0 && containsHelper(s, substr))
|
||||
}
|
||||
|
||||
func containsHelper(s, substr string) bool {
|
||||
for i := 0; i <= len(s)-len(substr); i++ {
|
||||
if s[i:i+len(substr)] == substr {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -225,8 +225,12 @@ func runSessionStop(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("Stopping session for %s/%s...\n", rigName, polecatName)
|
||||
if err := mgr.Stop(polecatName); err != nil {
|
||||
if sessionForce {
|
||||
fmt.Printf("Force stopping session for %s/%s...\n", rigName, polecatName)
|
||||
} else {
|
||||
fmt.Printf("Stopping session for %s/%s...\n", rigName, polecatName)
|
||||
}
|
||||
if err := mgr.Stop(polecatName, sessionForce); err != nil {
|
||||
return fmt.Errorf("stopping session: %w", err)
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,8 @@ func (m *Manager) Start(polecat string, opts StartOptions) error {
|
||||
}
|
||||
|
||||
// Stop terminates a polecat session.
|
||||
func (m *Manager) Stop(polecat string) error {
|
||||
// If force is true, skips graceful shutdown and kills immediately.
|
||||
func (m *Manager) Stop(polecat string, force bool) error {
|
||||
sessionID := m.sessionName(polecat)
|
||||
|
||||
// Check if session exists
|
||||
@@ -146,9 +147,11 @@ func (m *Manager) Stop(polecat string) error {
|
||||
return ErrSessionNotFound
|
||||
}
|
||||
|
||||
// Try graceful shutdown first
|
||||
m.tmux.SendKeysRaw(sessionID, "C-c") // Ctrl+C
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
// Try graceful shutdown first (unless forced)
|
||||
if !force {
|
||||
m.tmux.SendKeysRaw(sessionID, "C-c") // Ctrl+C
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
|
||||
// Kill the session
|
||||
if err := m.tmux.KillSession(sessionID); err != nil {
|
||||
@@ -237,7 +240,7 @@ func (m *Manager) Inject(polecat, message string) error {
|
||||
}
|
||||
|
||||
// StopAll terminates all sessions for this rig.
|
||||
func (m *Manager) StopAll() error {
|
||||
func (m *Manager) StopAll(force bool) error {
|
||||
infos, err := m.List()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -245,7 +248,7 @@ func (m *Manager) StopAll() error {
|
||||
|
||||
var lastErr error
|
||||
for _, info := range infos {
|
||||
if err := m.Stop(info.Polecat); err != nil {
|
||||
if err := m.Stop(info.Polecat, force); err != nil {
|
||||
lastErr = err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ func TestStopNotFound(t *testing.T) {
|
||||
}
|
||||
m := NewManager(tmux.NewTmux(), r)
|
||||
|
||||
err := m.Stop("Toast")
|
||||
err := m.Stop("Toast", false)
|
||||
if err != ErrSessionNotFound {
|
||||
t.Errorf("Stop = %v, want ErrSessionNotFound", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user