Skip to content

📋 ParseStatusOutput ​

Parses the text output of composer status to determine whether installed dependencies have local modifications, and returns *StatusResult.

When to use ​

Use this when you already have the output of composer status and need to programmatically detect whether dependency files in the vendor directory have been locally modified. Empty output means no modifications; any non-empty line indicates a modified file. It is the parser called internally by StatusStructured.

Signature ​

go
func ParseStatusOutput(output string) *StatusResult

Parameters ​

ParameterTypeDescription
outputstringThe raw output of composer status

Return value ​

  • *StatusResult: the status result, containing Modified (bool, true whenever the output is non-empty), Files ([]string, the list of modified files), and Output (the raw output).

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("status")
	if err != nil {
		log.Fatal(err)
	}

	result := composer.ParseStatusOutput(output)
	if result.Modified {
		fmt.Printf("Found %d locally modified files:\n", len(result.Files))
		for _, f := range result.Files {
			fmt.Println("  -", f)
		}
	} else {
		fmt.Println("No local modifications")
	}
}

Advanced ​

  • 🔍 Parsing logic: after TrimSpace, if empty → Modified=false; otherwise split by \n, add each non-empty line to Files, and set Modified=true.
  • 🚀 To execute the command and parse in one step, use StatusStructured(); to run with options, use StatusWithOptions(options).
  • 🔗 For related diagnostic parsers, see ParseDiagnoseOutput and ParseCheckOutput.

Released under the MIT License