diff --git a/pkg/cmd/extension/command.go b/pkg/cmd/extension/command.go index 8153ef5e4..9ac5e5f21 100644 --- a/pkg/cmd/extension/command.go +++ b/pkg/cmd/extension/command.go @@ -105,38 +105,20 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command { return err } if err := checkValidExtension(cmd.Root(), m, repo.RepoName()); err != nil { - // TODO i feel like this should check for a gh-foo script return err } - client, err := f.HttpClient() if err != nil { return fmt.Errorf("could not make http client: %w", err) } client = api.NewCachedClient(client, time.Second*30) - isBin, err := isBinExtension(client, repo) - if err != nil { - return fmt.Errorf("could not check for binary extension: %w", err) - } - if isBin { - return m.InstallBin(client, repo) - } - - hs, err := hasScript(client, repo) - if err != nil { - return err - } - if !hs { - return errors.New("extension is uninstallable: missing executable") - } - cfg, err := f.Config() if err != nil { return err } - protocol, _ := cfg.Get(repo.RepoHost(), "git_protocol") - return m.InstallGit(ghrepo.FormatRemoteURL(repo, protocol), io.Out, io.ErrOut) + + return m.Install(client, repo, io, cfg) }, }, func() *cobra.Command { diff --git a/pkg/cmd/extension/manager.go b/pkg/cmd/extension/manager.go index 393e8ef82..ddfbde3fc 100644 --- a/pkg/cmd/extension/manager.go +++ b/pkg/cmd/extension/manager.go @@ -19,6 +19,7 @@ import ( "github.com/cli/cli/v2/internal/ghrepo" "github.com/cli/cli/v2/pkg/extensions" "github.com/cli/cli/v2/pkg/findsh" + "github.com/cli/cli/v2/pkg/iostreams" "github.com/cli/safeexec" "gopkg.in/yaml.v3" ) @@ -187,6 +188,28 @@ type BinManifest struct { Path string } +func (m *Manager) Install(client *http.Client, repo ghrepo.Interface, io *iostreams.IOStreams, cfg config.Config) error { + isBin, err := isBinExtension(client, repo) + if err != nil { + return fmt.Errorf("could not check for binary extension: %w", err) + } + if isBin { + return m.InstallBin(client, repo) + } + + hs, err := hasScript(client, repo) + if err != nil { + return err + } + if !hs { + // TODO open an issue hint, here? + return errors.New("extension is uninstallable: missing executable") + } + + protocol, _ := cfg.Get(repo.RepoHost(), "git_protocol") + return m.InstallGit(ghrepo.FormatRemoteURL(repo, protocol), io.Out, io.ErrOut) +} + func (m *Manager) InstallBin(client *http.Client, repo ghrepo.Interface) error { var r *release r, err := fetchLatestRelease(client, repo) diff --git a/pkg/cmd/extension/manager_test.go b/pkg/cmd/extension/manager_test.go index c03d3fa62..80a535c40 100644 --- a/pkg/cmd/extension/manager_test.go +++ b/pkg/cmd/extension/manager_test.go @@ -44,7 +44,7 @@ func newTestManager(dir string) *Manager { return cmd }, platform: func() string { - return "amiga-arm64" + return "windows-amd64" }, } } @@ -222,7 +222,7 @@ func TestManager_InstallBin(t *testing.T) { release{ Assets: []releaseAsset{ { - Name: "gh-bin-ext-amiga-arm64", + Name: "gh-bin-ext-windows-amd64", APIURL: "https://example.com/release/cool", }, }, diff --git a/pkg/extensions/extension.go b/pkg/extensions/extension.go index 6102c1e9a..99087fe04 100644 --- a/pkg/extensions/extension.go +++ b/pkg/extensions/extension.go @@ -4,7 +4,9 @@ import ( "io" "net/http" + "github.com/cli/cli/v2/internal/config" "github.com/cli/cli/v2/internal/ghrepo" + "github.com/cli/cli/v2/pkg/iostreams" ) //go:generate moq -rm -out extension_mock.go . Extension @@ -19,8 +21,9 @@ type Extension interface { //go:generate moq -rm -out manager_mock.go . ExtensionManager type ExtensionManager interface { List(includeMetadata bool) []Extension - InstallGit(url string, stdout, stderr io.Writer) error - InstallBin(client *http.Client, repo ghrepo.Interface) error + Install(*http.Client, ghrepo.Interface, *iostreams.IOStreams, config.Config) error + InstallBin(*http.Client, ghrepo.Interface) error + InstallGit(string, io.Writer, io.Writer) error InstallLocal(dir string) error Upgrade(name string, force bool, stdout, stderr io.Writer) error Remove(name string) error