Skip to content

🔓 CheckLicenses — Check dependency license compatibility

🔍 CheckLicenses checks whether the licenses of all dependency packages in the project are compatible, equivalent to running composer licenses --check, commonly used for pre-release compliance review.

📋 Signature

go
func (c *Composer) CheckLicenses() (string, error)

📥 Parameters

ParameterTypeDescription
NoneThis method takes no parameters

📤 Return value

Return valueTypeDescription
First return valuestringText output of the license check result
Second return valueerrorReturned 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), use LicensesWithFormat(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), use LicensesWithOptions(options map[string]string).
  • 🔗 The underlying layer depends on the Run method to execute the command; the working directory and Composer binary path are determined by the Composer instance configuration.

Released under the MIT License