Skip to content

🔎 SearchOnlyName

Search packages on Packagist by package name only, without matching package descriptions. Equivalent to composer search <query> --only-name, suitable for scenarios that require exact name matching and reduced search noise.

📋 Signature

go
func (c *Composer) SearchOnlyName(query string) (string, error)

📥 Parameters

ParameterTypeDescription
querystringSearch keyword, e.g. "logger", "symfony/console"

📤 Return value

Return valueTypeDescription
First return valuestringStandard output text of composer search <query> --only-name, one matching package name per line
Second return valueerrorReturned when an error occurs during execution; nil indicates success

📝 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 Composer failed: %v", err)
	}

	output, err := comp.SearchOnlyName("logger")
	if err != nil {
		log.Fatalf("search packages by name failed: %v", err)
	}
	fmt.Println("search-by-name results:")
	fmt.Println(output)
}

🚀 Advanced

  • 📋 Regular search that matches both description and name: use Search.
  • 📦 When you need to parse results in JSON or other formats: use SearchWithFormat(query, format).
  • 🏷️ Filter by package type (e.g. library, composer-plugin): use SearchWithType.
  • ⚠️ This method only matches package names; packages whose descriptions contain the keyword but whose names do not match will not appear in the results. The result set is therefore usually smaller and more precise than Search.

Released under the MIT License