📜 LicensesWithFormat
Outputs dependency package license information in the specified format, equivalent to running composer licenses --format=<format>.
When to use
Use this when you need to export license information as JSON (for programmatic processing) or summary (for easy reading), etc.
Signature
go
func (c *Composer) LicensesWithFormat(format string) (string, error)Parameters
| Parameter | Type | Description |
|---|---|---|
format | string | Output format; common values: json, summary, text |
Return value
string: The raw output ofcomposer licensesin the corresponding format.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 in JSON format for easier downstream parsing
jsonOutput, err := comp.LicensesWithFormat("json")
if err != nil {
log.Fatalf("Failed to get license info: %v", err)
}
fmt.Println(jsonOutput)
}Advanced
- If you use the
jsonformat and want a struct directly, useGetLicensesInfo(which calls and parses internally). - For default plain-text output, use
Licenses. - To pass multiple options at once (e.g.
--format=json --no-dev), useLicensesWithOptions.