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

Function executable

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

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