🩺 ParseDiagnoseOutput
Parses the text output of composer diagnose, classifying lines into ok/warning/error/info check items, and returns *DiagnoseResult.
When to use
Use this when you already have the output of composer diagnose and need to programmatically determine the pass status of each check (HTTP, git, cache, etc.). It is the parser called internally by DiagnoseStructured.
Signature
go
func ParseDiagnoseOutput(output string) *DiagnoseResultParameters
| Parameter | Type | Description |
|---|---|---|
output | string | The raw output of composer diagnose |
Return value
*DiagnoseResult: the diagnosis result;Checksis[]DiagnoseCheck. EachDiagnoseCheckcontainsName,Status(ok/warning/error/info), andDetail(the full original line).
Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatal(err)
}
output, err := comp.Run("diagnose")
result := composer.ParseDiagnoseOutput(output)
for _, chk := range result.Checks {
icon := "ℹ️"
switch chk.Status {
case "ok":
icon = "✅"
case "warning":
icon = "⚠️"
case "error":
icon = "❌"
}
fmt.Printf("%s [%s] %s\n", icon, chk.Status, chk.Name)
}
}Advanced
- 🔍 Parsing logic: scans line by line and determines status by prefix —
[OK]/✓isok,[WARNING]/⚠iswarning,[ERROR]/✗iserror, and the rest areinfo. - 📋 If you only need the check item list (without the wrapper struct), use
ParseDiagnoseOutputAsChecks(output), which returnsresult.Checks. - 🚀 To execute the command and parse in one step, use
DiagnoseStructured(). - 🔗 For related health checks, see
HealthCheck(),ParseStatusOutput, andParseCheckOutput.