Skip to content

Commit

Permalink
Export Path function (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoe authored Jul 24, 2023
1 parent 7adca2a commit 27eb670
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down

0 comments on commit 27eb670

Please sign in to comment.