diff --git a/cmd/gh/main.go b/cmd/gh/main.go index 98dcc4034..218f3ed22 100644 --- a/cmd/gh/main.go +++ b/cmd/gh/main.go @@ -236,7 +236,7 @@ func mainRun() exitCode { newRelease := <-updateMessageChan if newRelease != nil { - isHomebrew := isUnderHomebrew(cmdFactory.Executable) + isHomebrew := isUnderHomebrew(cmdFactory.Executable()) if isHomebrew && isRecentRelease(newRelease.PublishedAt) { // do not notify Homebrew users before the version bump had a chance to get merged into homebrew-core return exitOK diff --git a/pkg/cmd/auth/login/login.go b/pkg/cmd/auth/login/login.go index ad6aec33d..08bcf1dfd 100644 --- a/pkg/cmd/auth/login/login.go +++ b/pkg/cmd/auth/login/login.go @@ -38,8 +38,6 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm IO: f.IOStreams, Config: f.Config, HttpClient: f.HttpClient, - - MainExecutable: f.Executable, } var tokenStdin bool @@ -103,6 +101,7 @@ func NewCmdLogin(f *cmdutil.Factory, runF func(*LoginOptions) error) *cobra.Comm } } + opts.MainExecutable = f.Executable() if runF != nil { return runF(opts) } diff --git a/pkg/cmd/auth/login/login_test.go b/pkg/cmd/auth/login/login_test.go index c3cde03cf..f6fbcabd5 100644 --- a/pkg/cmd/auth/login/login_test.go +++ b/pkg/cmd/auth/login/login_test.go @@ -147,7 +147,8 @@ func Test_NewCmdLogin(t *testing.T) { t.Run(tt.name, func(t *testing.T) { io, stdin, _, _ := iostreams.Test() f := &cmdutil.Factory{ - IOStreams: io, + IOStreams: io, + Executable: func() string { return "/path/to/gh" }, } io.SetStdoutTTY(true) diff --git a/pkg/cmd/auth/refresh/refresh.go b/pkg/cmd/auth/refresh/refresh.go index a756c30b1..4ece13384 100644 --- a/pkg/cmd/auth/refresh/refresh.go +++ b/pkg/cmd/auth/refresh/refresh.go @@ -36,7 +36,6 @@ func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra. _, err := authflow.AuthFlowWithConfig(cfg, io, hostname, "", scopes) return err }, - MainExecutable: f.Executable, } cmd := &cobra.Command{ @@ -62,6 +61,7 @@ func NewCmdRefresh(f *cmdutil.Factory, runF func(*RefreshOptions) error) *cobra. return &cmdutil.FlagError{Err: errors.New("--hostname required when not running interactively")} } + opts.MainExecutable = f.Executable() if runF != nil { return runF(opts) } diff --git a/pkg/cmd/auth/refresh/refresh_test.go b/pkg/cmd/auth/refresh/refresh_test.go index 02941cd9b..943864424 100644 --- a/pkg/cmd/auth/refresh/refresh_test.go +++ b/pkg/cmd/auth/refresh/refresh_test.go @@ -88,7 +88,8 @@ func Test_NewCmdRefresh(t *testing.T) { t.Run(tt.name, func(t *testing.T) { io, _, _, _ := iostreams.Test() f := &cmdutil.Factory{ - IOStreams: io, + IOStreams: io, + Executable: func() string { return "/path/to/gh" }, } io.SetStdinTTY(tt.tty) io.SetStdoutTTY(tt.tty) diff --git a/pkg/cmd/factory/default.go b/pkg/cmd/factory/default.go index 64cb2f0a7..08d93c2be 100644 --- a/pkg/cmd/factory/default.go +++ b/pkg/cmd/factory/default.go @@ -19,12 +19,17 @@ import ( ) func New(appVersion string) *cmdutil.Factory { + var exe string f := &cmdutil.Factory{ - Config: configFunc(), // No factory dependencies - Branch: branchFunc(), // No factory dependencies - Executable: executable("gh"), // No factory dependencies - - ExtensionManager: extension.NewManager(), + Config: configFunc(), // No factory dependencies + Branch: branchFunc(), // No factory dependencies + Executable: func() string { + if exe != "" { + return exe + } + exe = executable("gh") + return exe + }, } f.IOStreams = ioStreams(f) // Depends on Config diff --git a/pkg/cmdutil/factory.go b/pkg/cmdutil/factory.go index 2430a2150..83d4a638f 100644 --- a/pkg/cmdutil/factory.go +++ b/pkg/cmdutil/factory.go @@ -27,5 +27,5 @@ type Factory struct { ExtensionManager extensions.ExtensionManager // Executable is the path to the currently invoked gh binary - Executable string + Executable func() string }