Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #159 from puppetlabs/gh-137/main/order_tool_list
Browse files Browse the repository at this point in the history
(GH-137) Fix tool listing order
  • Loading branch information
chelnak authored May 3, 2022
2 parents dbb83fb + ab67e42 commit 51f63dd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pkg/prm/prm.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ func (*Prm) FormatTools(tools map[string]*Tool, jsonOutput string) (string, erro
table := tablewriter.NewWriter(stringBuilder)
table.SetHeader([]string{"DisplayName", "Author", "Name", "Project_URL", "Version"})
table.SetBorder(false)
for _, value := range tools {
sortedTools := sortTools(tools)
for _, value := range sortedTools {
table.Append([]string{value.Cfg.Plugin.Display, value.Cfg.Plugin.Author, value.Cfg.Plugin.Id, value.Cfg.Plugin.UpstreamProjUrl, value.Cfg.Plugin.Version})
}
table.Render()
Expand All @@ -312,3 +313,16 @@ func (*Prm) FormatTools(tools map[string]*Tool, jsonOutput string) (string, erro
}
return output, nil
}

func sortTools(tools map[string]*Tool) []*Tool {
var sortedTools []*Tool
for _, tool := range tools {
sortedTools = append(sortedTools, tool)
}

sort.Slice(sortedTools, func(i, j int) bool {
return sortedTools[i].Cfg.Plugin.Display < sortedTools[j].Cfg.Plugin.Display
})

return sortedTools
}

0 comments on commit 51f63dd

Please sign in to comment.