fix: respect GT_TOWN_ROOT in quick-add command (#840)
The quick-add command (used by shell hook's "Add to Gas Town?" prompt) previously only checked hardcoded paths ~/gt and ~/gastown, ignoring GT_TOWN_ROOT and any other Gas Town installations. This caused rigs to be added to the wrong town when users had multiple Gas Town installations (e.g., ~/gt and ~/Documents/code/gt). Fix the town discovery order: 1. GT_TOWN_ROOT env var (explicit user preference) 2. workspace.FindFromCwd() (supports multiple installations) 3. Fall back to ~/gt and ~/gastown
This commit is contained in:
@@ -165,6 +165,19 @@ func sanitizeRigName(name string) string {
|
||||
}
|
||||
|
||||
func findOrCreateTown() (string, error) {
|
||||
// Priority 1: GT_TOWN_ROOT env var (explicit user preference)
|
||||
if townRoot := os.Getenv("GT_TOWN_ROOT"); townRoot != "" {
|
||||
if isValidTown(townRoot) {
|
||||
return townRoot, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 2: Try to find from cwd (supports multiple town installations)
|
||||
if townRoot, err := workspace.FindFromCwd(); err == nil && townRoot != "" {
|
||||
return townRoot, nil
|
||||
}
|
||||
|
||||
// Priority 3: Fall back to well-known locations
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -176,11 +189,17 @@ func findOrCreateTown() (string, error) {
|
||||
}
|
||||
|
||||
for _, path := range candidates {
|
||||
mayorDir := filepath.Join(path, "mayor")
|
||||
if _, err := os.Stat(mayorDir); err == nil {
|
||||
if isValidTown(path) {
|
||||
return path, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", fmt.Errorf("no Gas Town found - run 'gt install ~/gt' first")
|
||||
}
|
||||
|
||||
// isValidTown checks if a path is a valid Gas Town installation.
|
||||
func isValidTown(path string) bool {
|
||||
mayorDir := filepath.Join(path, "mayor")
|
||||
_, err := os.Stat(mayorDir)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user