🏷️ SearchWithType
Search packages of a specific type on Packagist by keyword. Equivalent to composer search <query> --type=<packageType>, useful for searching only libraries, plugins (composer-plugin), project templates (project), and other specific types.
📋 Signature
go
func (c *Composer) SearchWithType(query string, packageType string) (string, error)📥 Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | Search keyword, e.g. "logger" |
packageType | string | Package type, e.g. "library", "composer-plugin", "project", "metapackage" |
📤 Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Standard output text of composer search <query> --type=<packageType> |
| 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)
}
// Only search packages of the composer-plugin type
output, err := comp.SearchWithType("logger", "composer-plugin")
if err != nil {
log.Fatalf("search packages by type failed: %v", err)
}
fmt.Println("search results for the specified type:")
fmt.Println(output)
}🚀 Advanced
- 📋 Regular search without type restriction: use Search.
- 🔎 Match package names only and filter out description noise: use SearchOnlyName.
- 📦 When you need results in
jsonformat for programmatic parsing: useSearchWithFormat(query, format). - ⚠️
packageTypeis appended to the command line as--type=<packageType>. Passing an empty string results in--type=, which may cause Composer to error. Always pass a valid type value.