📈 CheckForOutdatedPackages
Checks for outdated dependency packages in the project and shows available updates. Equivalent to running composer outdated [--direct] [--minor-only] [--format <format>].
When to use
Use when you need to report in a cron job or dashboard "how many dependencies can be upgraded and what the latest versions are". Parameters let you control whether to only check direct dependencies, only minor updates, and the output format.
Signature
go
func (c *Composer) CheckForOutdatedPackages(direct bool, minor bool, format string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
direct | bool | true checks only direct dependencies, false checks all dependencies |
minor | bool | true shows only minor version updates (same major version), false shows all |
format | string | Output format, e.g. "text", "json"; an empty string means the parameter is not passed |
Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Outdated package list (text or JSON) |
| Second return value | error | Returned when execution fails |
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.Fatalf("init failed: %v", err)
}
// Check minor updates of direct dependencies, JSON format
output, err := comp.CheckForOutdatedPackages(true, true, "json")
if err != nil {
log.Fatalf("failed to check outdated packages: %v", err)
}
fmt.Println(output)
}Advanced
- For structured results (including package name, current version, latest version), use
GetOutdatedInfo()orGetOutdatedInfoWithOptions(options), which return an*OutdatedResult. - For text output only, use
OutdatedPackages()orOutdatedPackagesDirect(). - To customize more options, use
OutdatedWithOptions(options).