From 27eb6700797589acf8ea84c05dee9aa7ed9b9677 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Mon, 24 Jul 2023 10:21:52 -0700 Subject: [PATCH] Export Path function (#123) --- gh.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/gh.go b/gh.go index a4c900f..b176780 100644 --- a/gh.go +++ b/gh.go @@ -18,7 +18,7 @@ import ( // Exec invokes a gh command in a subprocess and captures the output and error streams. func Exec(args ...string) (stdout, stderr bytes.Buffer, err error) { - ghExe, err := ghLookPath() + ghExe, err := Path() if err != nil { return } @@ -28,7 +28,7 @@ func Exec(args ...string) (stdout, stderr bytes.Buffer, err error) { // ExecContext invokes a gh command in a subprocess and captures the output and error streams. func ExecContext(ctx context.Context, args ...string) (stdout, stderr bytes.Buffer, err error) { - ghExe, err := ghLookPath() + ghExe, err := Path() if err != nil { return } @@ -39,14 +39,16 @@ func ExecContext(ctx context.Context, args ...string) (stdout, stderr bytes.Buff // Exec invokes a gh command in a subprocess with its stdin, stdout, and stderr streams connected to // those of the parent process. This is suitable for running gh commands with interactive prompts. func ExecInteractive(ctx context.Context, args ...string) error { - ghExe, err := ghLookPath() + ghExe, err := Path() if err != nil { return err } return run(ctx, ghExe, nil, os.Stdin, os.Stdout, os.Stderr, args) } -func ghLookPath() (string, error) { +// Path searches for an executable named "gh" in the directories named by the PATH environment variable. +// If the executable is found the result is an absolute path. +func Path() (string, error) { if ghExe := os.Getenv("GH_PATH"); ghExe != "" { return ghExe, nil }