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

Function executable

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

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