summaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
authorAlex Goodman <wagoodman@users.noreply.github.com>2018-12-08 11:46:09 -0500
committerGitHub <noreply@github.com>2018-12-08 11:46:09 -0500
commit9f9a8f2c05ddf4d997fa55fb43946f81fa02237b (patch)
tree9ba3b684a014d09d561667e9153920889544d814 /cmd
parent910c33fdf0889e925e8b423a6f94ddccd9df5be7 (diff)
Refactor image preprocessing (#121)
Diffstat (limited to 'cmd')
-rw-r--r--cmd/analyze.go27
-rw-r--r--cmd/build.go11
-rw-r--r--cmd/root.go2
3 files changed, 29 insertions, 11 deletions
diff --git a/cmd/analyze.go b/cmd/analyze.go
index 0e45139..ab28979 100644
--- a/cmd/analyze.go
+++ b/cmd/analyze.go
@@ -10,9 +10,9 @@ import (
"github.com/wagoodman/dive/utils"
)
-// analyze takes a docker image tag, digest, or id and displays the
+// doAnalyzeCmd takes a docker image tag, digest, or id and displays the
// image analysis to the screen
-func analyze(cmd *cobra.Command, args []string) {
+func doAnalyzeCmd(cmd *cobra.Command, args []string) {
defer utils.Cleanup()
if len(args) == 0 {
printVersionFlag, err := cmd.PersistentFlags().GetBool("version")
@@ -33,6 +33,25 @@ func analyze(cmd *cobra.Command, args []string) {
utils.Exit(1)
}
color.New(color.Bold).Println("Analyzing Image")
- manifest, refTrees, efficiency, inefficiencies := image.InitializeData(userImage)
- ui.Run(manifest, refTrees, efficiency, inefficiencies)
+
+ ui.Run(fetchAndAnalyze(userImage))
+}
+
+func fetchAndAnalyze(imageID string) *image.AnalysisResult {
+ analyzer := image.GetAnalyzer(imageID)
+
+ fmt.Println(" Fetching image...")
+ err := analyzer.Parse(imageID)
+ if err != nil {
+ fmt.Printf("cannot fetch image: %v\n", err)
+ utils.Exit(1)
+ }
+
+ fmt.Println(" Analyzing image...")
+ result, err := analyzer.Analyze()
+ if err != nil {
+ fmt.Printf("cannot doAnalyzeCmd image: %v\n", err)
+ utils.Exit(1)
+ }
+ return result
}
diff --git a/cmd/build.go b/cmd/build.go
index c982df8..680fc5f 100644
--- a/cmd/build.go
+++ b/cmd/build.go
@@ -4,7 +4,6 @@ import (
"github.com/fatih/color"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
- "github.com/wagoodman/dive/image"
"github.com/wagoodman/dive/ui"
"github.com/wagoodman/dive/utils"
"io/ioutil"
@@ -16,15 +15,15 @@ var buildCmd = &cobra.Command{
Use: "build [any valid `docker build` arguments]",
Short: "Builds and analyzes a docker image from a Dockerfile (this is a thin wrapper for the `docker build` command).",
DisableFlagParsing: true,
- Run: doBuild,
+ Run: doBuildCmd,
}
func init() {
rootCmd.AddCommand(buildCmd)
}
-// doBuild implements the steps taken for the build command
-func doBuild(cmd *cobra.Command, args []string) {
+// doBuildCmd implements the steps taken for the build command
+func doBuildCmd(cmd *cobra.Command, args []string) {
defer utils.Cleanup()
iidfile, err := ioutil.TempFile("/tmp", "dive.*.iid")
if err != nil {
@@ -47,6 +46,6 @@ func doBuild(cmd *cobra.Command, args []string) {
}
color.New(color.Bold).Println("Analyzing Image")
- manifest, refTrees, efficiency, inefficiencies := image.InitializeData(string(imageId))
- ui.Run(manifest, refTrees, efficiency, inefficiencies)
+
+ ui.Run(fetchAndAnalyze(string(imageId)))
}
diff --git a/cmd/root.go b/cmd/root.go
index 5e27ac6..1ec4d3f 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -22,7 +22,7 @@ var rootCmd = &cobra.Command{
Long: `This tool provides a way to discover and explore the contents of a docker image. Additionally the tool estimates
the amount of wasted space and identifies the offending files from the image.`,
Args: cobra.MaximumNArgs(1),
- Run: analyze,
+ Run: doAnalyzeCmd,
}
// Execute adds all child commands to the root command and sets flags appropriately.