refactor(cmd): extract common manager creation boilerplate

Add getRig() helper in rig_helpers.go that encapsulates the common
boilerplate for finding town root, loading rigs config, and retrieving
a rig. This reduces duplication across 5 get*Manager functions:
- getPolecatManager
- getSessionManager
- getCrewManager
- getRefineryManager
- getWitnessManager

Closes gt-7sqi.

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Steve Yegge
2025-12-21 21:45:52 -08:00
parent 5850f8e67b
commit bb7f197eef
6 changed files with 51 additions and 95 deletions

View File

@@ -114,22 +114,9 @@ func init() {
// getRefineryManager creates a refinery manager for a rig.
func getRefineryManager(rigName string) (*refinery.Manager, *rig.Rig, error) {
townRoot, err := workspace.FindFromCwdOrError()
_, r, err := getRig(rigName)
if err != nil {
return nil, nil, fmt.Errorf("not in a Gas Town workspace: %w", err)
}
rigsConfigPath := filepath.Join(townRoot, "mayor", "rigs.json")
rigsConfig, err := config.LoadRigsConfig(rigsConfigPath)
if err != nil {
rigsConfig = &config.RigsConfig{Rigs: make(map[string]config.RigEntry)}
}
g := git.NewGit(townRoot)
rigMgr := rig.NewManager(townRoot, rigsConfig, g)
r, err := rigMgr.GetRig(rigName)
if err != nil {
return nil, nil, fmt.Errorf("rig '%s' not found", rigName)
return nil, nil, err
}
mgr := refinery.NewManager(r)