🔎 ShowPackage
Shows detailed information for a given package (version, dependencies, install location, etc.). Equivalent to composer show package/name.
When to use
- 📋 Troubleshoot the current version and source of an installed package.
- 🔍 Confirm whether a package is abandoned.
- 🧩 View a package's own dependency list.
Signature
go
func (c *Composer) ShowPackage(packageName string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
packageName | string | Name of the package to display information for |
Return value
| Value | Type | Description |
|---|---|---|
| Output | string | Standard output of composer show pkg |
| Error | error | Returned when an error occurs while fetching package information |
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)
}
output, err := comp.ShowPackage("symfony/console")
if err != nil {
log.Fatalf("get package info failed: %v", err)
}
fmt.Println("package info:", output)
}Advanced
Structured results
When you need field-level data, use ShowPackageInfo instead. It runs composer show pkg --format=json internally and parses the output into *PackageInfo.
Specifying a format
ShowPackageWithFormat(packageName, format) lets you specify the json / text output format:
go
output, err := comp.ShowPackageWithFormat("symfony/console", "json")🔍 Related methods
ShowPackageInfo: structured package information.ShowDependencyTree: view a package's dependency chain as a tree.