Skip to content

📜 Licenses

Lists the license information of the current project's dependency packages, equivalent to running composer licenses.

When to use

Use this for compliance review before release, or to generate a third-party license list (e.g. for deliverables or legal). The output is a plain-text table.

Signature

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

Parameters

This method takes no parameters.

Return value

  • string: The raw text output of composer licenses, including each dependency's package name, version, and license.
  • error: Returns the corresponding error message when an error occurs during command execution.

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("Initialization failed: %v", err)
	}

	output, err := comp.Licenses()
	if err != nil {
		log.Fatalf("Failed to get license info: %v", err)
	}

	fmt.Println("Dependency license info:")
	fmt.Println(output)
}

Advanced

  • To specify the output format (such as json or summary), use LicensesWithFormat.
  • For structured results (*LicensesResult), use GetLicensesInfo.
  • To check license compatibility, use CheckLicenses (composer licenses --check).
  • To pass multiple custom options, use LicensesWithOptions.

Released under the MIT License