feat: allow witness restart agent override
This commit is contained in:
@@ -759,7 +759,7 @@ func runRigBoot(cmd *cobra.Command, args []string) error {
|
||||
} else {
|
||||
fmt.Printf(" Starting witness...\n")
|
||||
witMgr := witness.NewManager(r)
|
||||
if err := witMgr.Start(false); err != nil {
|
||||
if err := witMgr.Start(false, ""); err != nil {
|
||||
if err == witness.ErrAlreadyRunning {
|
||||
skipped = append(skipped, "witness (already running)")
|
||||
} else {
|
||||
@@ -839,7 +839,7 @@ func runRigStart(cmd *cobra.Command, args []string) error {
|
||||
} else {
|
||||
fmt.Printf(" Starting witness...\n")
|
||||
witMgr := witness.NewManager(r)
|
||||
if err := witMgr.Start(false); err != nil {
|
||||
if err := witMgr.Start(false, ""); err != nil {
|
||||
if err == witness.ErrAlreadyRunning {
|
||||
skipped = append(skipped, "witness")
|
||||
} else {
|
||||
@@ -1418,7 +1418,7 @@ func runRigRestart(cmd *cobra.Command, args []string) error {
|
||||
skipped = append(skipped, "witness")
|
||||
} else {
|
||||
fmt.Printf(" Starting witness...\n")
|
||||
if err := witMgr.Start(false); err != nil {
|
||||
if err := witMgr.Start(false, ""); err != nil {
|
||||
if err == witness.ErrAlreadyRunning {
|
||||
skipped = append(skipped, "witness")
|
||||
} else {
|
||||
|
||||
@@ -235,7 +235,7 @@ func startRigAgents(t *tmux.Tmux, townRoot string) {
|
||||
fmt.Printf(" %s %s witness already running\n", style.Dim.Render("○"), r.Name)
|
||||
} else {
|
||||
witMgr := witness.NewManager(r)
|
||||
if err := witMgr.Start(false); err != nil {
|
||||
if err := witMgr.Start(false, ""); err != nil {
|
||||
if err == witness.ErrAlreadyRunning {
|
||||
fmt.Printf(" %s %s witness already running\n", style.Dim.Render("○"), r.Name)
|
||||
} else {
|
||||
|
||||
@@ -118,7 +118,7 @@ func runUp(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
mgr := witness.NewManager(r)
|
||||
if err := mgr.Start(false); err != nil {
|
||||
if err := mgr.Start(false, ""); err != nil {
|
||||
if err == witness.ErrAlreadyRunning {
|
||||
printStatus(fmt.Sprintf("Witness (%s)", rigName), true, mgr.SessionName())
|
||||
} else {
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
var (
|
||||
witnessForeground bool
|
||||
witnessStatusJSON bool
|
||||
witnessAgentOverride string
|
||||
)
|
||||
|
||||
var witnessCmd = &cobra.Command{
|
||||
@@ -93,7 +94,8 @@ var witnessRestartCmd = &cobra.Command{
|
||||
Stops the current session (if running) and starts a fresh one.
|
||||
|
||||
Examples:
|
||||
gt witness restart greenplace`,
|
||||
gt witness restart greenplace
|
||||
gt witness restart greenplace --agent codex`,
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: runWitnessRestart,
|
||||
}
|
||||
@@ -105,6 +107,9 @@ func init() {
|
||||
// Status flags
|
||||
witnessStatusCmd.Flags().BoolVar(&witnessStatusJSON, "json", false, "Output as JSON")
|
||||
|
||||
// Restart flags
|
||||
witnessRestartCmd.Flags().StringVar(&witnessAgentOverride, "agent", "", "Agent alias to run the Witness with (overrides town default)")
|
||||
|
||||
// Add subcommands
|
||||
witnessCmd.AddCommand(witnessStartCmd)
|
||||
witnessCmd.AddCommand(witnessStopCmd)
|
||||
@@ -136,7 +141,7 @@ func runWitnessStart(cmd *cobra.Command, args []string) error {
|
||||
|
||||
fmt.Printf("Starting witness for %s...\n", rigName)
|
||||
|
||||
if err := mgr.Start(witnessForeground); err != nil {
|
||||
if err := mgr.Start(witnessForeground, ""); err != nil {
|
||||
if err == witness.ErrAlreadyRunning {
|
||||
fmt.Printf("%s Witness is already running\n", style.Dim.Render("⚠"))
|
||||
fmt.Printf(" %s\n", style.Dim.Render("Use 'gt witness attach' to connect"))
|
||||
@@ -289,7 +294,7 @@ func runWitnessAttach(cmd *cobra.Command, args []string) error {
|
||||
sessionName := witnessSessionName(rigName)
|
||||
|
||||
// Ensure session exists (creates if needed)
|
||||
if err := mgr.Start(false); err != nil && err != witness.ErrAlreadyRunning {
|
||||
if err := mgr.Start(false, ""); err != nil && err != witness.ErrAlreadyRunning {
|
||||
return err
|
||||
} else if err == nil {
|
||||
fmt.Printf("Started witness session for %s\n", rigName)
|
||||
@@ -322,7 +327,7 @@ func runWitnessRestart(cmd *cobra.Command, args []string) error {
|
||||
_ = mgr.Stop()
|
||||
|
||||
// Start fresh
|
||||
if err := mgr.Start(false); err != nil {
|
||||
if err := mgr.Start(false, witnessAgentOverride); err != nil {
|
||||
return fmt.Errorf("starting witness: %w", err)
|
||||
}
|
||||
|
||||
|
||||
19
internal/cmd/witness_test.go
Normal file
19
internal/cmd/witness_test.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWitnessRestartAgentFlag(t *testing.T) {
|
||||
flag := witnessRestartCmd.Flags().Lookup("agent")
|
||||
if flag == nil {
|
||||
t.Fatal("expected witness restart to define --agent flag")
|
||||
}
|
||||
if flag.DefValue != "" {
|
||||
t.Errorf("expected default agent override to be empty, got %q", flag.DefValue)
|
||||
}
|
||||
if !strings.Contains(flag.Usage, "overrides town default") {
|
||||
t.Errorf("expected --agent usage to mention overrides town default, got %q", flag.Usage)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user