MCPcopy Create free account
hub / github.com/cli/cli / installBin

Method installBin

pkg/cmd/extension/manager.go:283–384  ·  view source on GitHub ↗
(repo ghrepo.Interface, target string)

Source from the content-addressed store, hash-verified

281}
282
283func (m *Manager) installBin(repo ghrepo.Interface, target string) error {
284 var r *release
285 var err error
286 isPinned := target != ""
287 if isPinned {
288 r, err = fetchReleaseFromTag(m.client, repo, target)
289 } else {
290 r, err = fetchLatestRelease(m.client, repo)
291 }
292 if err != nil {
293 return err
294 }
295
296 platform, ext := m.platform()
297 isMacARM := platform == "darwin-arm64"
298 trueARMBinary := false
299
300 var asset *releaseAsset
301 for _, a := range r.Assets {
302 if strings.HasSuffix(a.Name, platform+ext) {
303 asset = &a
304 trueARMBinary = isMacARM
305 break
306 }
307 }
308
309 // if using an ARM-based Mac and an arm64 binary is unavailable, fall back to amd64 if a relevant binary is available and Rosetta 2 is installed
310 if asset == nil && isMacARM {
311 for _, a := range r.Assets {
312 if strings.HasSuffix(a.Name, darwinAmd64) {
313 if !hasRosetta() {
314 return fmt.Errorf(
315 "%[1]s unsupported for %[2]s. Install Rosetta with `softwareupdate --install-rosetta` to use the available %[3]s binary, or open an issue: `gh issue create -R %[4]s/%[1]s -t'Support %[2]s'`",
316 repo.RepoName(), platform, darwinAmd64, repo.RepoOwner())
317 }
318
319 fallbackMessage := fmt.Sprintf("%[1]s not available for %[2]s. Falling back to compatible %[3]s binary", repo.RepoName(), platform, darwinAmd64)
320 fmt.Fprintln(m.io.Out, fallbackMessage)
321
322 asset = &a
323 break
324 }
325 }
326 }
327
328 if asset == nil {
329 cs := m.io.ColorScheme()
330 errorMessageInRed := fmt.Sprintf(cs.Red("%[1]s unsupported for %[2]s."), repo.RepoName(), platform)
331 issueCreateCommand := generateMissingBinaryIssueCreateCommand(repo.RepoOwner(), repo.RepoName(), platform)
332
333 return fmt.Errorf(
334 "%[1]s\n\nTo request support for %[2]s, open an issue on the extension's repo by running the following command:\n\n `%[3]s`",
335 errorMessageInRed, platform, issueCreateCommand)
336 }
337
338 if m.dryRunMode {
339 return nil
340 }

Callers 3

InstallMethod · 0.95
upgradeExtensionMethod · 0.95
upgradeBinExtensionMethod · 0.95

Calls 15

installDirMethod · 0.95
NewImmutableSafeURLFunction · 0.92
fetchReleaseFromTagFunction · 0.85
fetchLatestReleaseFunction · 0.85
codesignBinaryFunction · 0.85
writeManifestFunction · 0.85
ColorSchemeMethod · 0.80
RedMethod · 0.80
JoinMethod · 0.80
downloadAssetFunction · 0.70

Tested by

no test coverage detected