(c flags.FlagContext)
| 58 | } |
| 59 | |
| 60 | func (cmd *Plugins) Execute(c flags.FlagContext) error { |
| 61 | var version string |
| 62 | |
| 63 | cmd.ui.Say(T("Listing Installed Plugins...")) |
| 64 | |
| 65 | plugins := cmd.config.Plugins() |
| 66 | |
| 67 | var table *terminal.UITable |
| 68 | if c.Bool("checksum") { |
| 69 | cmd.ui.Say(T("Computing sha1 for installed plugins, this may take a while ...")) |
| 70 | table = cmd.ui.Table([]string{T("Plugin Name"), T("Version"), T("Command Name"), "sha1", T("Command Help")}) |
| 71 | } else { |
| 72 | table = cmd.ui.Table([]string{T("Plugin Name"), T("Version"), T("Command Name"), T("Command Help")}) |
| 73 | } |
| 74 | |
| 75 | sortedPluginNames := make([]string, 0, len(plugins)) |
| 76 | for k := range plugins { |
| 77 | sortedPluginNames = append(sortedPluginNames, k) |
| 78 | } |
| 79 | sort.Slice(sortedPluginNames, sorting.SortAlphabeticFunc(sortedPluginNames)) |
| 80 | |
| 81 | for _, pluginName := range sortedPluginNames { |
| 82 | metadata := plugins[pluginName] |
| 83 | if metadata.Version.Major == 0 && metadata.Version.Minor == 0 && metadata.Version.Build == 0 { |
| 84 | version = "N/A" |
| 85 | } else { |
| 86 | version = fmt.Sprintf("%d.%d.%d", metadata.Version.Major, metadata.Version.Minor, metadata.Version.Build) |
| 87 | } |
| 88 | |
| 89 | for _, command := range metadata.Commands { |
| 90 | args := []string{pluginName, version} |
| 91 | |
| 92 | if command.Alias != "" { |
| 93 | args = append(args, command.Name+", "+command.Alias) |
| 94 | } else { |
| 95 | args = append(args, command.Name) |
| 96 | } |
| 97 | |
| 98 | if c.Bool("checksum") { |
| 99 | checksum := util.NewSha1Checksum(metadata.Location) |
| 100 | sha1, err := checksum.ComputeFileSha1() |
| 101 | if err != nil { |
| 102 | args = append(args, "n/a") |
| 103 | } else { |
| 104 | args = append(args, fmt.Sprintf("%x", sha1)) |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | args = append(args, command.HelpText) |
| 109 | table.Add(args...) |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | cmd.ui.Ok() |
| 114 | cmd.ui.Say("") |
| 115 | |
| 116 | err := table.Print() |
| 117 | if err != nil { |
nothing calls this directly
no test coverage detected