Skip to content

🔎 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

ParameterTypeDescription
packageNamestringName of the package to display information for

Return value

ValueTypeDescription
OutputstringStandard output of composer show pkg
ErrorerrorReturned 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")

Released under the MIT License