Skip to content

📋 GetInstalledPackageNames

Gets the list of all installed package names, equivalent to running composer show and parsing the output to extract package names.

When to use

Use it when you only need the list of package names without full package information. It is more efficient than getting the full output, and is suitable for batch package existence checks, dependency inventory generation, and similar scenarios.

Signature

go
func (c *Composer) GetInstalledPackageNames() ([]string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return value[]stringList of installed package names (including direct and transitive dependencies)
Second return valueerrorReturned when executing composer show 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("initialization failed: %v", err)
	}

	packages, err := comp.GetInstalledPackageNames()
	if err != nil {
		log.Fatalf("failed to get package list: %v", err)
	}
	fmt.Printf("%d packages installed in total:\n", len(packages))
	for _, name := range packages {
		fmt.Println(" -", name)
	}
}

Advanced

Released under the MIT License