mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 22:46:36 +01:00
add analysis coordination (with dummy analyzer)
This commit is contained in:
+45
-6
@@ -4,6 +4,12 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/anchore/imgbom/internal"
|
||||
|
||||
"github.com/anchore/imgbom/imgbom"
|
||||
"github.com/anchore/imgbom/imgbom/scope"
|
||||
"github.com/anchore/stereoscope"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
@@ -11,13 +17,22 @@ const ApplicationName = "imgbom"
|
||||
|
||||
var rootOptions struct {
|
||||
cfgFile string
|
||||
scope string
|
||||
}
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: ApplicationName,
|
||||
Short: "A container image BOM tool",
|
||||
Long: `todo.`,
|
||||
Run: doRunCmd,
|
||||
Use: fmt.Sprintf("%s [IMAGE]", ApplicationName),
|
||||
Short: "A container image BOM tool", // TODO: add copy
|
||||
Long: internal.Tprintf(`\
|
||||
Supports the following image sources:
|
||||
{{.appName}} yourrepo/yourimage:tag defaults to using images from a docker daemon
|
||||
{{.appName}} docker://yourrepo/yourimage:tag explicitly use the docker daemon
|
||||
{{.appName}} tar://path/to/yourimage.tar use a tarball from disk
|
||||
`, map[string]interface{}{
|
||||
"appName": ApplicationName,
|
||||
}),
|
||||
Args: cobra.MaximumNArgs(1),
|
||||
Run: doRunCmd,
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
@@ -29,13 +44,37 @@ func Execute() {
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(loadApplicationConfig)
|
||||
rootCmd.PersistentFlags().StringVar(&rootOptions.cfgFile, "config", "", "config file")
|
||||
// TODO: add config support
|
||||
//rootCmd.PersistentFlags().StringVarP(&rootOptions.cfgFile, "config", "c", "", "config file")
|
||||
|
||||
// scan options
|
||||
rootCmd.Flags().StringVarP(&rootOptions.scope, "scope", "s", scope.AllLayersScope.String(),
|
||||
fmt.Sprintf("selection of layers to analyze, options=%v", scope.Options))
|
||||
}
|
||||
|
||||
func loadApplicationConfig() {
|
||||
// TODO...
|
||||
// TODO: add config support
|
||||
}
|
||||
|
||||
func doRunCmd(cmd *cobra.Command, args []string) {
|
||||
img, err := stereoscope.GetImage(args[0])
|
||||
if err != nil {
|
||||
// TODO: replace with log and exit
|
||||
panic(err)
|
||||
}
|
||||
|
||||
scopeOption := scope.ParseOption(rootOptions.scope)
|
||||
if scopeOption == scope.UnknownScope {
|
||||
// TODO: replace with log and exit
|
||||
panic(scopeOption)
|
||||
}
|
||||
|
||||
catalog, err := imgbom.CatalogImage(img, scopeOption)
|
||||
if err != nil {
|
||||
// TODO: replace with log and exit
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// TODO: remove this with presenter implementation
|
||||
fmt.Printf("%+v\n", catalog)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user