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

Method Upgrade

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

Source from the content-addressed store, hash-verified

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