dive/cmd/analyze.go
Alex Goodman d5e8a92968
Rework CI validation workflow and makefile (#460)
* rework CI validation workflow and makefile

* enable push

* fix job names

* fix license check

* fix snapshot builds

* fix acceptance tests

* fix linting

* disable pull request event

* rework windows runner caching

* disable release pipeline and add issue templates
2023-07-06 22:01:46 -04:00

74 lines
1.6 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/wagoodman/dive/dive"
"github.com/wagoodman/dive/runtime"
)
// doAnalyzeCmd takes a docker image tag, digest, or id and displays the
// image analysis to the screen
func doAnalyzeCmd(cmd *cobra.Command, args []string) {
if len(args) == 0 {
printVersionFlag, err := cmd.PersistentFlags().GetBool("version")
if err == nil && printVersionFlag {
printVersion(cmd, args)
return
}
fmt.Println("No image argument given")
os.Exit(1)
}
userImage := args[0]
if userImage == "" {
fmt.Println("No image argument given")
os.Exit(1)
}
initLogging()
isCi, ciConfig, err := configureCi()
if err != nil {
fmt.Printf("ci configuration error: %v\n", err)
os.Exit(1)
}
var sourceType dive.ImageSource
var imageStr string
sourceType, imageStr = dive.DeriveImageSource(userImage)
if sourceType == dive.SourceUnknown {
sourceStr := viper.GetString("source")
sourceType = dive.ParseImageSource(sourceStr)
if sourceType == dive.SourceUnknown {
fmt.Printf("unable to determine image source: %v\n", sourceStr)
os.Exit(1)
}
imageStr = userImage
}
ignoreErrors, err := cmd.PersistentFlags().GetBool("ignore-errors")
if err != nil {
logrus.Error("unable to get 'ignore-errors' option:", err)
}
runtime.Run(runtime.Options{
Ci: isCi,
Source: sourceType,
Image: imageStr,
ExportFile: exportFile,
CiConfig: ciConfig,
IgnoreErrors: viper.GetBool("ignore-errors") || ignoreErrors,
})
}