Skip to content

📜 Licenses

列出当前项目依赖包的许可证信息,相当于执行 composer licenses

何时使用

当你在发布前做合规审查、生成第三方许可证清单(如用于交付物或法务)时使用。输出为纯文本表格。

签名

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

参数

该方法不接受任何参数。

返回值

  • stringcomposer licenses 的原始文本输出,包含各依赖包名、版本与许可证。
  • error:执行命令过程中发生错误时返回相应错误信息。

示例

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("初始化失败: %v", err)
	}

	output, err := comp.Licenses()
	if err != nil {
		log.Fatalf("获取许可证信息失败: %v", err)
	}

	fmt.Println("依赖许可证信息:")
	fmt.Println(output)
}

进阶

  • 需要指定输出格式(如 jsonsummary)时用 LicensesWithFormat
  • 需要结构化结果(*LicensesResult)用 GetLicensesInfo
  • 检查许可证兼容性用 CheckLicensescomposer licenses --check)。
  • 传入多个自定义选项用 LicensesWithOptions

基于 MIT 许可证发布