(r *inventory.Inventory)
| 170 | } |
| 171 | |
| 172 | func generateToolsDoc(r *inventory.Inventory) string { |
| 173 | tools := r.ToolsForRegistration(context.Background()) |
| 174 | if len(tools) == 0 { |
| 175 | return "" |
| 176 | } |
| 177 | |
| 178 | var buf strings.Builder |
| 179 | var toolBuf strings.Builder |
| 180 | var currentToolsetID inventory.ToolsetID |
| 181 | var currentToolsetIcon string |
| 182 | firstSection := true |
| 183 | |
| 184 | writeSection := func() { |
| 185 | if toolBuf.Len() == 0 { |
| 186 | return |
| 187 | } |
| 188 | if !firstSection { |
| 189 | buf.WriteString("\n\n") |
| 190 | } |
| 191 | firstSection = false |
| 192 | sectionName := formatToolsetName(string(currentToolsetID)) |
| 193 | icon := octiconImg(currentToolsetIcon) |
| 194 | if icon != "" { |
| 195 | icon += " " |
| 196 | } |
| 197 | fmt.Fprintf(&buf, "<details>\n\n<summary>%s%s</summary>\n\n%s\n\n</details>", icon, sectionName, strings.TrimSuffix(toolBuf.String(), "\n\n")) |
| 198 | toolBuf.Reset() |
| 199 | } |
| 200 | |
| 201 | for _, tool := range tools { |
| 202 | // When toolset changes, emit the previous section |
| 203 | if tool.Toolset.ID != currentToolsetID { |
| 204 | writeSection() |
| 205 | currentToolsetID = tool.Toolset.ID |
| 206 | currentToolsetIcon = tool.Toolset.Icon |
| 207 | } |
| 208 | writeToolDoc(&toolBuf, tool) |
| 209 | toolBuf.WriteString("\n\n") |
| 210 | } |
| 211 | |
| 212 | // Emit the last section |
| 213 | writeSection() |
| 214 | |
| 215 | return buf.String() |
| 216 | } |
| 217 | |
| 218 | func writeToolDoc(buf *strings.Builder, tool inventory.ServerTool) { |
| 219 | // Tool name (no icon - section header already has the toolset icon) |
no test coverage detected