findLocalCheatpath walks upward from dir looking for a .cheat directory. It returns the path to the first .cheat directory found, or an empty string if none exists. This mirrors the discovery pattern used by git for .git directories.
(dir string)
| 133 | // if none exists. This mirrors the discovery pattern used by git for .git |
| 134 | // directories. |
| 135 | func findLocalCheatpath(dir string) string { |
| 136 | for { |
| 137 | candidate := filepath.Join(dir, ".cheat") |
| 138 | if info, err := os.Stat(candidate); err == nil && info.IsDir() { |
| 139 | return candidate |
| 140 | } |
| 141 | parent := filepath.Dir(dir) |
| 142 | if parent == dir { |
| 143 | return "" |
| 144 | } |
| 145 | dir = parent |
| 146 | } |
| 147 | } |
no outgoing calls