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

Method Upgrade

pkg/cmd/extension/manager.go:460–486  ·  view source on GitHub ↗
(name string, force bool)

Source from the content-addressed store, hash-verified

458var noExtensionsInstalledError = errors.New("no extensions installed")
459
460func (m *Manager) Upgrade(name string, force bool) error {
461 // Fetch metadata during list only when upgrading all extensions.
462 // This is a performance improvement so that we don't make a
463 // bunch of unnecessary network requests when trying to upgrade a single extension.
464 fetchMetadata := name == ""
465 exts, _ := m.list(fetchMetadata)
466 if len(exts) == 0 {
467 return noExtensionsInstalledError
468 }
469 if name == "" {
470 return m.upgradeExtensions(exts, force)
471 }
472 for _, f := range exts {
473 if f.Name() != name {
474 continue
475 }
476 if f.IsLocal() {
477 return localExtensionUpgradeError
478 }
479 // For single extensions manually retrieve latest version since we forgo doing it during list.
480 if latestVersion := f.LatestVersion(); latestVersion == "" {
481 return fmt.Errorf("unable to retrieve latest version for extension %q", name)
482 }
483 return m.upgradeExtensions([]*Extension{f}, force)
484 }
485 return fmt.Errorf("no extension matched %q", name)
486}
487
488func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error {
489 var longestExt = slices.MaxFunc(exts, func(a, b *Extension) int {

Callers

nothing calls this directly

Calls 6

listMethod · 0.95
upgradeExtensionsMethod · 0.95
NameMethod · 0.65
IsLocalMethod · 0.65
LatestVersionMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected