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

Method installBin

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

Source from the content-addressed store, hash-verified

276}
277
278func (m *Manager) installBin(repo ghrepo.Interface, target string) error {
279 var r *release
280 var err error
281 isPinned := target != ""
282 if isPinned {
283 r, err = fetchReleaseFromTag(m.client, repo, target)
284 } else {
285 r, err = fetchLatestRelease(m.client, repo)
286 }
287 if err != nil {
288 return err
289 }
290
291 platform, ext := m.platform()
292 isMacARM := platform == "darwin-arm64"
293 trueARMBinary := false
294
295 var asset *releaseAsset
296 for _, a := range r.Assets {
297 if strings.HasSuffix(a.Name, platform+ext) {
298 asset = &a
299 trueARMBinary = isMacARM
300 break
301 }
302 }
303
304 // 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
305 if asset == nil && isMacARM {
306 for _, a := range r.Assets {
307 if strings.HasSuffix(a.Name, darwinAmd64) {
308 if !hasRosetta() {
309 return fmt.Errorf(
310 "%[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'`",
311 repo.RepoName(), platform, darwinAmd64, repo.RepoOwner())
312 }
313
314 fallbackMessage := fmt.Sprintf("%[1]s not available for %[2]s. Falling back to compatible %[3]s binary", repo.RepoName(), platform, darwinAmd64)
315 fmt.Fprintln(m.io.Out, fallbackMessage)
316
317 asset = &a
318 break
319 }
320 }
321 }
322
323 if asset == nil {
324 cs := m.io.ColorScheme()
325 errorMessageInRed := fmt.Sprintf(cs.Red("%[1]s unsupported for %[2]s."), repo.RepoName(), platform)
326 issueCreateCommand := generateMissingBinaryIssueCreateCommand(repo.RepoOwner(), repo.RepoName(), platform)
327
328 return fmt.Errorf(
329 "%[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`",
330 errorMessageInRed, platform, issueCreateCommand)
331 }
332
333 if m.dryRunMode {
334 return nil
335 }

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