FindFinch finds the installation path of Finch.
(deps FinchFinderDeps)
| 86 | |
| 87 | // FindFinch finds the installation path of Finch. |
| 88 | func FindFinch(deps FinchFinderDeps) (Finch, error) { |
| 89 | exe, err := deps.Executable() |
| 90 | if err != nil { |
| 91 | return "", fmt.Errorf("failed to locate the executable that starts this process: %w", err) |
| 92 | } |
| 93 | realPath, err := deps.EvalSymlinks(exe) |
| 94 | if err != nil { |
| 95 | return "", fmt.Errorf("failed to find the real path of the executable: %w", err) |
| 96 | } |
| 97 | // The directory structure is finch_home/bin/finch, |
| 98 | // where the last path comment (i.e., finch) is the executable that starts this process. |
| 99 | res := deps.FilePathJoin(realPath, "..", "..") |
| 100 | return Finch(res), nil |
| 101 | } |