Merge remote-tracking branch 'origin/polecat/Warboy'
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -20,6 +21,13 @@ import (
|
|||||||
"github.com/steveyegge/gastown/internal/workspace"
|
"github.com/steveyegge/gastown/internal/workspace"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// polecatNames are Mad Max: Fury Road themed names for auto-generated polecats.
|
||||||
|
var polecatNames = []string{
|
||||||
|
"Nux", "Toast", "Capable", "Cheedo", "Dag", "Rictus", "Slit", "Morsov",
|
||||||
|
"Ace", "Coma", "Valkyrie", "Keeper", "Vuvalini", "Organic", "Immortan",
|
||||||
|
"Corpus", "Doof", "Scabrous", "Splendid", "Fragile",
|
||||||
|
}
|
||||||
|
|
||||||
// Spawn command flags
|
// Spawn command flags
|
||||||
var (
|
var (
|
||||||
spawnIssue string
|
spawnIssue string
|
||||||
@@ -103,9 +111,16 @@ func runSpawn(cmd *cobra.Command, args []string) error {
|
|||||||
if polecatName == "" {
|
if polecatName == "" {
|
||||||
polecatName, err = selectIdlePolecat(polecatMgr, r)
|
polecatName, err = selectIdlePolecat(polecatMgr, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("auto-select polecat: %w", err)
|
// If --create is set, generate a new polecat name instead of failing
|
||||||
|
if spawnCreate {
|
||||||
|
polecatName = generatePolecatName(polecatMgr)
|
||||||
|
fmt.Printf("Generated polecat name: %s\n", polecatName)
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("auto-select polecat: %w", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("Auto-selected polecat: %s\n", polecatName)
|
||||||
}
|
}
|
||||||
fmt.Printf("Auto-selected polecat: %s\n", polecatName)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check/create polecat
|
// Check/create polecat
|
||||||
@@ -204,6 +219,38 @@ func parseSpawnAddress(addr string) (rigName, polecatName string, err error) {
|
|||||||
return addr, "", nil
|
return addr, "", nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generatePolecatName generates a unique polecat name that doesn't conflict with existing ones.
|
||||||
|
func generatePolecatName(mgr *polecat.Manager) string {
|
||||||
|
existing, _ := mgr.List()
|
||||||
|
existingNames := make(map[string]bool)
|
||||||
|
for _, p := range existing {
|
||||||
|
existingNames[p.Name] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try to find an unused name from the list
|
||||||
|
// Shuffle to avoid always picking the same name
|
||||||
|
shuffled := make([]string, len(polecatNames))
|
||||||
|
copy(shuffled, polecatNames)
|
||||||
|
rand.Shuffle(len(shuffled), func(i, j int) {
|
||||||
|
shuffled[i], shuffled[j] = shuffled[j], shuffled[i]
|
||||||
|
})
|
||||||
|
|
||||||
|
for _, name := range shuffled {
|
||||||
|
if !existingNames[name] {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// All names taken, generate one with a number suffix
|
||||||
|
base := shuffled[0]
|
||||||
|
for i := 2; ; i++ {
|
||||||
|
name := fmt.Sprintf("%s%d", base, i)
|
||||||
|
if !existingNames[name] {
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// selectIdlePolecat finds an idle polecat in the rig.
|
// selectIdlePolecat finds an idle polecat in the rig.
|
||||||
func selectIdlePolecat(mgr *polecat.Manager, r *rig.Rig) (string, error) {
|
func selectIdlePolecat(mgr *polecat.Manager, r *rig.Rig) (string, error) {
|
||||||
polecats, err := mgr.List()
|
polecats, err := mgr.List()
|
||||||
|
|||||||
Reference in New Issue
Block a user