🔓 CheckLicenses — Check dependency license compatibility
🔍
CheckLicenseschecks whether the licenses of all dependency packages in the project are compatible, equivalent to runningcomposer licenses --check, commonly used for pre-release compliance review.
📋 Signature
go
func (c *Composer) CheckLicenses() (string, error)📥 Parameters
| Parameter | Type | Description |
|---|---|---|
| None | — | This method takes no parameters |
📤 Return value
| Return value | Type | Description |
|---|---|---|
| First return value | string | Text output of the license check result |
| Second return value | error | Returned when an error occurs during execution; nil on success |
📝 Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.NewComposer()
if err != nil {
log.Fatalf("failed to create Composer instance: %v", err)
}
output, err := comp.CheckLicenses()
if err != nil {
log.Fatalf("failed to check licenses: %v", err)
}
fmt.Println("License check result:")
fmt.Println(output)
}🚀 Advanced
- 📋 If you only need to view the license list without a compatibility check, use
Licenses(); to specify a format (e.g.json), useLicensesWithFormat(format). - 🧪 Calling this method in a CI/CD pipeline can automatically block incompatible licenses before release (e.g. GPL slipping into a commercial project).
- ⚙️ To customize check options (e.g.
--no-dev), useLicensesWithOptions(options map[string]string). - 🔗 The underlying layer depends on the
Runmethod to execute the command; the working directory and Composer binary path are determined by theComposerinstance configuration.