MCPcopy Create free account
hub / github.com/cli/cli / executable

Function executable

internal/ghcmd/cmd.go:457–493  ·  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

455// auth login`, running `brew update` will print out authentication errors as git is unable to locate
456// Homebrew-installed `gh`
457func executable(fallback string) string {
458 exe, err := os.Executable()
459 if err != nil {
460 return fallback
461 }
462
463 base := filepath.Base(exe)
464 path := os.Getenv("PATH")
465 for _, dir := range filepath.SplitList(path) {
466 p, err := filepath.Abs(filepath.Join(dir, base))
467 if err != nil {
468 continue
469 }
470 f, err := os.Lstat(p)
471 if err != nil {
472 continue
473 }
474
475 if p == exe {
476 return p
477 } else if f.Mode()&os.ModeSymlink != 0 {
478 realP, err := filepath.EvalSymlinks(p)
479 if err != nil {
480 continue
481 }
482 realExe, err := filepath.EvalSymlinks(exe)
483 if err != nil {
484 continue
485 }
486 if realP == realExe {
487 return p
488 }
489 }
490 }
491
492 return exe
493}
494
495func mightBeGHESUser(cfg gh.Config) bool {
496 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 4

BaseMethod · 0.80
JoinMethod · 0.80
ModeMethod · 0.80
ExecutableMethod · 0.65

Tested by 2

Test_executableFunction · 0.56
Test_executable_relativeFunction · 0.56