Skip to content

📦 OutdatedPackagesDirect Show only outdated direct dependencies

🔍 OutdatedPackagesDirect shows only outdated packages among the dependencies directly declared in composer.json, excluding transitive dependencies. It is equivalent to running composer outdated --direct, suitable for quickly identifying your own dependencies that need updating.

📋 Signature

go
func (c *Composer) OutdatedPackagesDirect() (string, error)

📥 Parameters

ParameterTypeDescription
NoneThis method takes no parameters

📤 Return value

Return valueTypeDescription
First return valuestringThe text output of the outdated direct dependencies list
Second return valueerrorReturned when an error occurs during retrieval; nil on success

📝 Example

go
package main

import (
	"fmt"
	"log"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.NewComposer()
	if err != nil {
		log.Fatalf("failed to create Composer instance: %v", err)
	}

	output, err := comp.OutdatedPackagesDirect()
	if err != nil {
		log.Fatalf("failed to get outdated direct dependencies: %v", err)
	}
	fmt.Println("Outdated direct dependencies:")
	fmt.Println(output)
}

🚀 Advanced

  • 📋 To view all outdated packages including transitive dependencies, use OutdatedPackages().
  • 🧪 To output in json format for programmatic parsing, use ShowOutdatedWithFormat("json") or OutdatedWithFormat(format).
  • ⚙️ For custom combined options (e.g. --direct + --minor-only), use OutdatedWithOptions(options map[string]string) with {"direct": "", "minor-only": ""}.
  • 🔗 In a dependency update pipeline, first use this method to filter the direct dependency update list, then use Update([]string{...}, false) to update precisely.

Released under the MIT License