Skip to content

✅ 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) *CheckResult

Parameters

ParameterTypeDescription
outputstringThe raw output of composer check

Return value

  • *CheckResult: the check result; Valid defaults to true; Messages, Warnings, and Errors are []string. Lines containing error/Error/FAIL set Valid=false and are placed into Errors; lines containing warning/Warning/WARN are placed into Warnings; the rest go into Messages.

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. Valid is set to false only when an error keyword appears or the command returns a non-zero exit code (CheckStructured also folds the command error into the decision).
  • 🚀 To execute the command and parse in one step, use CheckStructured(); to run with options, use CheckWithOptions(options).
  • 📝 Note that composer check differs from composer validate: the former checks json/lock synchronization, the latter validates the schema. For schema validation, see ParseValidateOutput.
  • 🔗 For related diagnostic parsers, see ParseDiagnoseOutput and ParseStatusOutput.

Released under the MIT License