Introduce GH_PATH environment variable (#7025)

This commit is contained in:
Sam Coe 2023-03-07 11:30:10 +11:00 committed by GitHub
parent 4636931b02
commit 05bf29d88e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View file

@ -83,6 +83,9 @@ var HelpTopics = map[string]map[string]string{
"$XDG_CONFIG_HOME/gh" or "$HOME/.config/gh".
GH_PROMPT_DISABLED: set to any value to disable interactive prompting in the terminal.
GH_PATH: set the path to the gh executable, useful for when gh can not properly determine
its own path such as in the cygwin terminal.
`),
},
"reference": {

View file

@ -34,6 +34,10 @@ type Factory struct {
// Executable is the path to the currently invoked binary
func (f *Factory) Executable() string {
ghPath := os.Getenv("GH_PATH")
if ghPath != "" {
return ghPath
}
if !strings.ContainsRune(f.ExecutableName, os.PathSeparator) {
f.ExecutableName = executable(f.ExecutableName)
}

View file

@ -54,3 +54,12 @@ func Test_executable(t *testing.T) {
t.Errorf("executable() = %q, want %q", got, bin2Exe)
}
}
func Test_Executable_override(t *testing.T) {
override := strings.Join([]string{"C:", "cygwin64", "home", "gh.exe"}, string(os.PathSeparator))
t.Setenv("GH_PATH", override)
f := Factory{}
if got := f.Executable(); got != override {
t.Errorf("executable() = %q, want %q", got, override)
}
}