✅ ParseCheckOutput
Parses the text output of composer check, classifying lines into messages/warnings/errors, and returns *CheckResult.
When to use
Use this when you already have the output of composer check (used to check whether composer.json and composer.lock are in sync, etc.) and need to programmatically determine whether it passed and collect warning details. It is the parser called internally by CheckStructured.
Signature
go
func ParseCheckOutput(output string) *CheckResultParameters
| Parameter | Type | Description |
|---|---|---|
output | string | The raw output of composer check |
Return value
*CheckResult: the check result;Validdefaults totrue;Messages,Warnings, andErrorsare[]string. Lines containingerror/Error/FAILsetValid=falseand are placed intoErrors; lines containingwarning/Warning/WARNare placed intoWarnings; the rest go intoMessages.
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, _ := comp.Run("check")
result := composer.ParseCheckOutput(output)
if result.Valid {
fmt.Println("✅ Check passed")
} else {
fmt.Println("❌ Check did not pass")
for _, e := range result.Errors {
fmt.Println("Error:", e)
}
}
for _, w := range result.Warnings {
fmt.Println("Warning:", w)
}
}Advanced
- 🔍 The parsing logic is based on keyword substring matching (two sets, case-sensitive and case-insensitive) and does not depend on JSON.
Validis set tofalseonly when an error keyword appears or the command returns a non-zero exit code (CheckStructuredalso folds the command error into the decision). - 🚀 To execute the command and parse in one step, use
CheckStructured(); to run with options, useCheckWithOptions(options). - 📝 Note that
composer checkdiffers fromcomposer validate: the former checks json/lock synchronization, the latter validates the schema. For schema validation, seeParseValidateOutput. - 🔗 For related diagnostic parsers, see
ParseDiagnoseOutputandParseStatusOutput.