Skip to content

🔄 ParseUpdateOutput

Parses the text output of composer update, extracting the count of updated packages and warning information, and returns *UpdateResult.

When to use

Use this when you already have the full output of composer update and need to programmatically count how many packages were updated this run and whether there are warnings. It is similar to ParseInstallOutput but only focuses on the update count.

Signature

go
func ParseUpdateOutput(output string) *UpdateResult

Parameters

ParameterTypeDescription
outputstringThe raw output of composer update

Return value

  • *UpdateResult: the update result, containing PackagesUpdated (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("update", "symfony/console")
	if err != nil {
		log.Printf("update returned error: %v (continue parsing output)", err)
	}

	result := composer.ParseUpdateOutput(output)
	fmt.Printf("Updated %d packages\n", result.PackagesUpdated)
	for _, w := range result.Warnings {
		fmt.Println("Warning:", w)
	}
}

Advanced

  • 🔍 Parsing logic: uses the regex (\d+)\s+update to match the Package operations: X updates line; scans line by line for lines containing Warning.
  • ⚠️ The parser never returns an error — when no match is found, PackagesUpdated is 0. Note that update may also perform install/remove actions, but this parser only counts the update count; for the full three-way count, use ParseInstallOutput.
  • 🔗 For single-package require/remove parsing, see ParseRequireOutput and ParseRemoveOutput.

Released under the MIT License