Skip to content

💡 Suggests

Views packages suggested for installation by the current project's dependencies. Equivalent to running composer suggests. These packages are not required dependencies, but installing them can enhance the functionality of certain packages (e.g. enabling extra extensions, providing better performance).

📋 Signature

go
func (c *Composer) Suggests() error

📥 Parameters

ParameterTypeDescription
NoneThis method takes no parameters

📤 Return value

Return valueTypeDescription
Sole return valueerrorReturned when an error occurs during execution; nil indicates success

Difference from other commands

This method only returns error rather than (string, error), because suggestion information is typically presented to developers via Composer's standard output for manual decision-making, with no need for further programmatic processing. If you need the output text, use c.Run("suggests") instead.

📝 Example

go
package main

import (
	"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)
	}

	if err := comp.Suggests(); err != nil {
		log.Fatalf("view suggested packages failed: %v", err)
	}
}

🚀 Advanced

  • 📦 To actually install a suggested package: use RequirePackage (composer require <package>).
  • 🎁 View donatable packages in the project: use FundPackages (composer fund).
  • 🔍 Call this after composer install or composer update to discover suggestions introduced by new dependencies.
  • ⚠️ composer suggests writes to standard output by default; this method discards the output text and only cares whether execution succeeded. To keep the output, use the underlying Run method directly.

Released under the MIT License