MCPcopy Index your code
hub / github.com/cli/cli / executable

Function executable

internal/ghcmd/cmd.go:441–477  ·  view source on GitHub ↗

Finds the location of the executable for the current process as it's found in PATH, respecting symlinks. If the process couldn't determine its location, return fallbackName. If the executable wasn't found in PATH, return the absolute location to the program. The idea is that the result of this func

(fallback string)

Source from the content-addressed store, hash-verified

439// auth login`, running `brew update` will print out authentication errors as git is unable to locate
440// Homebrew-installed `gh`
441func executable(fallback string) string {
442 exe, err := os.Executable()
443 if err != nil {
444 return fallback
445 }
446
447 base := filepath.Base(exe)
448 path := os.Getenv("PATH")
449 for _, dir := range filepath.SplitList(path) {
450 p, err := filepath.Abs(filepath.Join(dir, base))
451 if err != nil {
452 continue
453 }
454 f, err := os.Lstat(p)
455 if err != nil {
456 continue
457 }
458
459 if p == exe {
460 return p
461 } else if f.Mode()&os.ModeSymlink != 0 {
462 realP, err := filepath.EvalSymlinks(p)
463 if err != nil {
464 continue
465 }
466 realExe, err := filepath.EvalSymlinks(exe)
467 if err != nil {
468 continue
469 }
470 if realP == realExe {
471 return p
472 }
473 }
474 }
475
476 return exe
477}
478
479func mightBeGHESUser(cfg gh.Config) bool {
480 if os.Getenv("GH_ENTERPRISE_TOKEN") != "" || os.Getenv("GITHUB_ENTERPRISE_TOKEN") != "" {

Callers 3

Test_executableFunction · 0.70
Test_executable_relativeFunction · 0.70
executablePathFunction · 0.70

Calls 3

BaseMethod · 0.80
JoinMethod · 0.80
ExecutableMethod · 0.65

Tested by 2

Test_executableFunction · 0.56
Test_executable_relativeFunction · 0.56