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

Method installBin

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

Source from the content-addressed store, hash-verified

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

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