🔎 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
| Parameter | Type | Description |
|---|---|---|
query | string | Search keyword, e.g. "logger", "symfony/console" |
📤 Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Standard output text of composer search <query> --only-name, one matching package name per line |
| Second return value | error | Returned 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.