Skip to content

📦 ParseInstallOutput

Parses the text output of composer install, extracting the counts of installed/updated/removed packages and warning information, and returns *InstallResult.

When to use

Use this when you already have the full output of composer install and need to programmatically count how many packages were installed this run and whether there are warnings. It is commonly used in CI pipelines to log install results or decide whether to retry.

Signature

go
func ParseInstallOutput(output string) *InstallResult

Parameters

ParameterTypeDescription
outputstringThe raw output of composer install

Return value

  • *InstallResult: the install result, containing PackagesInstalled, PackagesUpdated, PackagesRemoved (all int), Output (the raw output), and Warnings ([]string, lines containing the word Warning).

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("install")
	if err != nil {
		log.Printf("install returned error: %v (continue parsing output)", err)
	}

	result := composer.ParseInstallOutput(output)
	fmt.Printf("installed %d, updated %d, removed %d\n",
		result.PackagesInstalled, result.PackagesUpdated, result.PackagesRemoved)
	for _, w := range result.Warnings {
		fmt.Println("Warning:", w)
	}
}

Advanced

  • 🔍 Parsing logic: uses the regex (\d+)\s+install/update/removal to match the Package operations: X installs, Y updates, Z removals line; scans line by line for lines containing Warning and collects them into Warnings.
  • ⚠️ The parser never returns an error — when no match is found, the count fields are 0. Callers should combine the return error of the install command itself to determine success or failure.
  • 🔗 For the corresponding update parser, see ParseUpdateOutput.

Released under the MIT License