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

Method Upgrade

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

Source from the content-addressed store, hash-verified

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