MCPcopy
hub / github.com/cli/cli / officialExtensionStubRun

Function officialExtensionStubRun

pkg/cmd/root/official_extension_stub.go:39–76  ·  view source on GitHub ↗
(io *iostreams.IOStreams, p prompter.Prompter, em extensions.ExtensionManager, ext *extensions.OfficialExtension)

Source from the content-addressed store, hash-verified

37}
38
39func officialExtensionStubRun(io *iostreams.IOStreams, p prompter.Prompter, em extensions.ExtensionManager, ext *extensions.OfficialExtension) error {
40 stderr := io.ErrOut
41
42 // In CI, skip the prompt so agents and CI runners don't block on Y/n.
43 if !ci.IsCI() {
44 if io.CanPrompt() {
45 prompt := heredoc.Docf(`
46 %[1]s is available as an official extension.
47 Would you like to install it now?
48 `, fmt.Sprintf("gh %s", ext.Name))
49 confirmed, err := p.Confirm(prompt, true)
50 if err != nil {
51 return err
52 }
53 if !confirmed {
54 return nil
55 }
56 } else {
57 fmt.Fprint(stderr, heredoc.Docf(`
58 %[1]s is available as an official extension.
59 To install it, run:
60 gh extension install %[2]s/%[3]s
61 `, fmt.Sprintf("gh %s", ext.Name), ext.Owner, ext.Repo))
62 return cmdutil.SilentError
63 }
64 }
65
66 repo := ext.Repository()
67 io.StartProgressIndicatorWithLabel(fmt.Sprintf("Installing %s/%s...", ext.Owner, ext.Repo))
68 installErr := em.Install(repo, "")
69 io.StopProgressIndicator()
70 if installErr != nil {
71 return fmt.Errorf("failed to install extension: %w", installErr)
72 }
73
74 fmt.Fprintf(stderr, "Successfully installed %s/%s\n", ext.Owner, ext.Repo)
75 return nil
76}

Callers 2

Calls 8

IsCIFunction · 0.92
CanPromptMethod · 0.80
RepositoryMethod · 0.80
ConfirmMethod · 0.65
InstallMethod · 0.65
StopProgressIndicatorMethod · 0.65
ErrorfMethod · 0.65

Tested by 1