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

Function executable

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

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