Skip to content

🩺 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) *DiagnoseResult

Parameters

ParameterTypeDescription
outputstringThe raw output of composer diagnose

Return value

  • *DiagnoseResult: the diagnosis result; Checks is []DiagnoseCheck. Each DiagnoseCheck contains Name, Status (ok/warning/error/info), and Detail (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]/ is ok, [WARNING]/ is warning, [ERROR]/ is error, and the rest are info.
  • 📋 If you only need the check item list (without the wrapper struct), use ParseDiagnoseOutputAsChecks(output), which returns result.Checks.
  • 🚀 To execute the command and parse in one step, use DiagnoseStructured().
  • 🔗 For related health checks, see HealthCheck(), ParseStatusOutput, and ParseCheckOutput.

Released under the MIT License