| 26 | var alreadyInstalledError = errors.New("alreadyInstalledError") |
| 27 | |
| 28 | func NewCmdExtension(f *cmdutil.Factory) *cobra.Command { |
| 29 | m := f.ExtensionManager |
| 30 | io := f.IOStreams |
| 31 | gc := f.GitClient |
| 32 | prompter := f.Prompter |
| 33 | config := f.Config |
| 34 | browser := f.Browser |
| 35 | httpClient := f.HttpClient |
| 36 | |
| 37 | extCmd := cobra.Command{ |
| 38 | Use: "extension", |
| 39 | Short: "Manage gh extensions", |
| 40 | Long: heredoc.Docf(` |
| 41 | GitHub CLI extensions are repositories that provide additional gh commands. |
| 42 | |
| 43 | The name of the extension repository must start with %[1]sgh-%[1]s and it must contain an |
| 44 | executable of the same name. All arguments passed to the %[1]sgh <extname>%[1]s invocation |
| 45 | will be forwarded to the %[1]sgh-<extname>%[1]s executable of the extension. |
| 46 | |
| 47 | An extension cannot override any of the core gh commands. If an extension name conflicts |
| 48 | with a core gh command, you can use %[1]sgh extension exec <extname>%[1]s. |
| 49 | |
| 50 | When an extension is executed, gh will check for new versions once every 24 hours and display |
| 51 | an upgrade notice. See %[1]sgh help environment%[1]s for information on disabling extension notices. |
| 52 | |
| 53 | Extensions are not verified, signed, or endorsed by GitHub. When you install or upgrade |
| 54 | an extension, you are trusting its publisher. It is your responsibility to review the |
| 55 | source and provenance of any extension before use. |
| 56 | |
| 57 | For the list of available extensions, see <https://github.com/topics/gh-extension>. |
| 58 | `, "`"), |
| 59 | Aliases: []string{"extensions", "ext"}, |
| 60 | } |
| 61 | |
| 62 | upgradeFunc := func(name string, flagForce bool) error { |
| 63 | cs := io.ColorScheme() |
| 64 | err := m.Upgrade(name, flagForce) |
| 65 | if err != nil { |
| 66 | if name != "" { |
| 67 | fmt.Fprintf(io.ErrOut, "%s Failed upgrading extension %s: %s\n", cs.FailureIcon(), name, err) |
| 68 | } else if errors.Is(err, noExtensionsInstalledError) { |
| 69 | return cmdutil.NewNoResultsError("no installed extensions found") |
| 70 | } else { |
| 71 | fmt.Fprintf(io.ErrOut, "%s Failed upgrading extensions\n", cs.FailureIcon()) |
| 72 | } |
| 73 | return cmdutil.SilentError |
| 74 | } |
| 75 | |
| 76 | if io.IsStdoutTTY() { |
| 77 | fmt.Fprintf(io.Out, "%s Successfully checked extension upgrades\n", cs.SuccessIcon()) |
| 78 | } |
| 79 | |
| 80 | return nil |
| 81 | } |
| 82 | |
| 83 | extCmd.AddCommand( |
| 84 | func() *cobra.Command { |
| 85 | query := search.Query{ |