🔄 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) *UpdateResultParameters
| Parameter | Type | Description |
|---|---|---|
output | string | The raw output of composer update |
Return value
*UpdateResult: the update result, containingPackagesUpdated(int),Output(the raw output), andWarnings([]string, lines containing the wordWarning).
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+updateto match thePackage operations: X updatesline; scans line by line for lines containingWarning. - ⚠️ The parser never returns an error — when no match is found,
PackagesUpdatedis 0. Note thatupdatemay also perform install/remove actions, but this parser only counts theupdatecount; for the full three-way count, useParseInstallOutput. - 🔗 For single-package require/remove parsing, see
ParseRequireOutputandParseRemoveOutput.