MCPcopy
hub / github.com/cli/cli / installBin

Method installBin

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

Source from the content-addressed store, hash-verified

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

Callers 3

InstallMethod · 0.95
upgradeExtensionMethod · 0.95
upgradeBinExtensionMethod · 0.95

Calls 15

installDirMethod · 0.95
fetchReleaseFromTagFunction · 0.85
fetchLatestReleaseFunction · 0.85
codesignBinaryFunction · 0.85
writeManifestFunction · 0.85
ColorSchemeMethod · 0.80
RedMethod · 0.80
JoinMethod · 0.80
downloadAssetFunction · 0.70
ErrorfMethod · 0.65

Tested by

no test coverage detected