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

Function resolveBinary

script/ghmock/run.go:424–449  ·  view source on GitHub ↗

resolveBinary turns a --gh value into an absolute path. A bare name is looked up on PATH.

(p string)

Source from the content-addressed store, hash-verified

422// resolveBinary turns a --gh value into an absolute path. A bare name is
423// looked up on PATH.
424func resolveBinary(p string) (string, error) {
425 var abs string
426 var err error
427 if !strings.ContainsRune(p, filepath.Separator) && !strings.Contains(p, "/") {
428 abs, err = exec.LookPath(p)
429 } else {
430 abs, err = filepath.Abs(p)
431 }
432 if err != nil {
433 return "", err
434 }
435 info, err := os.Stat(abs)
436 if err != nil {
437 return "", err
438 }
439 if info.IsDir() {
440 return "", fmt.Errorf("%s is a directory", abs)
441 }
442 if runtime.GOOS != "windows" && info.Mode()&0o111 == 0 {
443 return "", fmt.Errorf("%s is not executable", abs)
444 }
445 if err := checkBuildsDir(p, abs); err != nil {
446 return "", err
447 }
448 return abs, nil
449}
450
451// buildsDir, when set at build time with -ldflags "-X main.buildsDir=DIR",
452// limits --gh to binaries inside DIR. The issue-triage workflow sets it, so its

Callers 2

runBinaryFunction · 0.85
TestRunAllFunction · 0.85

Calls 5

checkBuildsDirFunction · 0.85
ContainsMethod · 0.80
IsDirMethod · 0.80
ModeMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestRunAllFunction · 0.68