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

Function executable

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

482// auth login`, running `brew update` will print out authentication errors as git is unable to locate
483// Homebrew-installed `gh`
484func executable(fallback string) string {
485 exe, err := os.Executable()
486 if err != nil {
487 return fallback
488 }
489
490 base := filepath.Base(exe)
491 path := os.Getenv("PATH")
492 for _, dir := range filepath.SplitList(path) {
493 p, err := filepath.Abs(filepath.Join(dir, base))
494 if err != nil {
495 continue
496 }
497 f, err := os.Lstat(p)
498 if err != nil {
499 continue
500 }
501
502 if p == exe {
503 return p
504 } else if f.Mode()&os.ModeSymlink != 0 {
505 realP, err := filepath.EvalSymlinks(p)
506 if err != nil {
507 continue
508 }
509 realExe, err := filepath.EvalSymlinks(exe)
510 if err != nil {
511 continue
512 }
513 if realP == realExe {
514 return p
515 }
516 }
517 }
518
519 return exe
520}
521
522func mightBeGHESUser(cfg gh.Config) bool {
523 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