📦 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) *InstallResultParameters
| Parameter | Type | Description |
|---|---|---|
output | string | The raw output of composer install |
Return value
*InstallResult: the install result, containingPackagesInstalled,PackagesUpdated,PackagesRemoved(allint),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("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/removalto match thePackage operations: X installs, Y updates, Z removalsline; scans line by line for lines containingWarningand collects them intoWarnings. - ⚠️ The parser never returns an error — when no match is found, the count fields are 0. Callers should combine the return error of the
installcommand itself to determine success or failure. - 🔗 For the corresponding update parser, see
ParseUpdateOutput.