()
| 67 | } |
| 68 | |
| 69 | func (p *pluginListOptions) run() error { |
| 70 | var op errors.Op = "commands.pluginListOptions.run" |
| 71 | if !p.dontUpdateIndex { |
| 72 | ec.Spin("Updating plugin index...") |
| 73 | err := p.EC.PluginsConfig.Repo.EnsureUpdated() |
| 74 | if err != nil { |
| 75 | p.EC.Logger.Warnf("unable to update plugin index %q", err) |
| 76 | } |
| 77 | } |
| 78 | ec.Spin("Fetching plugins list...") |
| 79 | defer ec.Spinner.Stop() |
| 80 | availablePlugins, err := ec.PluginsConfig.ListPlugins() |
| 81 | if err != nil { |
| 82 | return errors.E(op, fmt.Errorf("failed to load the list of plugins from the index: %w", err)) |
| 83 | } |
| 84 | names := make([]string, 0, len(availablePlugins)) |
| 85 | pluginMap := make(map[string]plugins.Plugin, len(availablePlugins)) |
| 86 | for i, ap := range availablePlugins { |
| 87 | names = append(names, i) |
| 88 | latestVersion := ap.Index[len(ap.Index)-1] |
| 89 | pluginMap[i] = ap.Versions[latestVersion] |
| 90 | } |
| 91 | installed, err := ec.PluginsConfig.ListInstalledPlugins() |
| 92 | if err != nil { |
| 93 | return errors.E(op, fmt.Errorf("failed to load installed plugins: %w", err)) |
| 94 | } |
| 95 | // No plugins found |
| 96 | if len(names) == 0 { |
| 97 | return nil |
| 98 | } |
| 99 | var rows [][]string |
| 100 | cols := []string{"NAME", "DESCRIPTION", "VERSION", "INSTALLED"} |
| 101 | for _, name := range names { |
| 102 | plugin := pluginMap[name] |
| 103 | var status string |
| 104 | var version string |
| 105 | if _, ok := installed[name]; ok { |
| 106 | status = "yes" |
| 107 | } else if _, ok, err := plugins.MatchPlatform(plugin.Platforms); err != nil { |
| 108 | return errors.E(op, fmt.Errorf("failed to get the matching platform for plugin %s: %w", name, err)) |
| 109 | } else if ok { |
| 110 | status = "no" |
| 111 | } else { |
| 112 | status = "unavailable on " + runtime.GOOS |
| 113 | } |
| 114 | if status == "yes" { |
| 115 | version = installed[name] |
| 116 | } else { |
| 117 | version = plugin.Version |
| 118 | } |
| 119 | rows = append(rows, []string{name, limitString(plugin.ShortDescription, 50), version, status}) |
| 120 | } |
| 121 | rows = sortByFirstColumn(rows) |
| 122 | ec.Spinner.Stop() |
| 123 | if err := printTable(p.EC.Stdout, cols, rows); err != nil { |
| 124 | return errors.E(op, err) |
| 125 | } |
| 126 | return nil |
no test coverage detected