Expand resolves a leading "~" segment to the user's home directory. Inputs of "" return "" so callers can guard against missing config paths without an extra branch.
(path string)
| 40 | // Inputs of "" return "" so callers can guard against missing config paths |
| 41 | // without an extra branch. |
| 42 | func Expand(path string) string { |
| 43 | if path == "" { |
| 44 | return "" |
| 45 | } |
| 46 | if path == "~" { |
| 47 | return Home() |
| 48 | } |
| 49 | if suffix, ok := strings.CutPrefix(path, "~/"); ok { |
| 50 | return joinHome(suffix) |
| 51 | } |
| 52 | return path |
| 53 | } |
| 54 | |
| 55 | // ConfigDir returns the directory in which CAM stores its primary config files. |
| 56 | // The CAM_CONFIG_DIR environment variable wins when set so tests can isolate |