mirror of
https://github.com/anchore/syft.git
synced 2026-10-30 14:02:26 +01:00
57 lines
1.7 KiB
Go
57 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/anchore/syft/cmd/syft/cli/convert"
|
|
"github.com/anchore/syft/cmd/syft/cli/options"
|
|
"github.com/anchore/syft/internal"
|
|
"github.com/anchore/syft/internal/config"
|
|
)
|
|
|
|
const (
|
|
convertExample = ` {{.appName}} {{.command}} img.syft.json -o spdx-json convert a syft SBOM to spdx-json, output goes to stdout in table format, by default
|
|
{{.appName}} {{.command}} img.syft.json -o cyclonedx-json=img.cdx.json convert a syft SBOM to CycloneDX, output goes to a file named img.cdx.json
|
|
`
|
|
)
|
|
|
|
//nolint:dupl
|
|
func Convert(v *viper.Viper, app *config.Application, ro *options.RootOptions, po *options.PackagesOptions) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "convert [SOURCE-SBOM] -o [FORMAT]",
|
|
Short: "Convert between SBOM formats",
|
|
Long: "[Experimental] Convert SBOM files to, and from, SPDX, CycloneDX and Syft's format. For more info about data loss between formats see https://github.com/anchore/syft#format-conversion-experimental",
|
|
Example: internal.Tprintf(convertExample, map[string]interface{}{
|
|
"appName": internal.ApplicationName,
|
|
"command": "convert",
|
|
}),
|
|
Args: func(cmd *cobra.Command, args []string) error {
|
|
if err := app.LoadAllValues(v, ro.Config); err != nil {
|
|
return fmt.Errorf("invalid application config: %w", err)
|
|
}
|
|
newLogWrapper(app)
|
|
logApplicationConfig(app)
|
|
return validateArgs(cmd, args)
|
|
},
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if app.CheckForAppUpdate {
|
|
checkForApplicationUpdate()
|
|
}
|
|
return convert.Run(cmd.Context(), app, args)
|
|
},
|
|
}
|
|
|
|
err := po.AddFlags(cmd, v)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
return cmd
|
|
}
|