cmd

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 1, 2017 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "[image1] [image2]",
	Short: "Compare two images.",
	Long:  `Compares two images using the specifed differs as indicated via flags (see iDiff documentation for available differs).`,
	Run: func(cmd *cobra.Command, args []string) {
		if validArgs, err := validateArgs(args); !validArgs {
			glog.Error(err.Error())
			os.Exit(1)
		}

		utils.SetDockerEngine(eng)

		img1Arg := args[0]
		img2Arg := args[1]
		diffArgs := []string{}
		allDiffers := getAllDiffers()
		for _, name := range allDiffers {
			if *diffFlagMap[name] == true {
				diffArgs = append(diffArgs, name)
			}
		}

		if len(diffArgs) == 0 {
			diffArgs = allDiffers
		}
		glog.Infof("Starting diff on images %s and %s, using differs: %s", img1Arg, img2Arg, diffArgs)
		image1, err := utils.ImagePrepper{img1Arg}.GetImage()
		if err != nil {
			glog.Error(err.Error())
			os.Exit(1)
		}
		image2, err := utils.ImagePrepper{img2Arg}.GetImage()
		if err != nil {
			glog.Error(err.Error())
			os.Exit(1)
		}
		diffTypes, err := differs.GetDiffers(diffArgs)
		if err != nil {
			glog.Error(err.Error())
			os.Exit(1)
		}

		req := differs.DiffRequest{image1, image2, diffTypes}
		if diffs, err := req.GetDiff(); err == nil {

			diffTypes := []string{}
			for name := range diffs {
				diffTypes = append(diffTypes, name)
			}
			sort.Strings(diffTypes)
			glog.Info("Retrieving diffs")
			diffResults := []utils.DiffResult{}
			for _, diffType := range diffTypes {
				diff := diffs[diffType]
				if json {
					diffResults = append(diffResults, diff.GetStruct())
				} else {
					err = diff.OutputText(diffType)
					if err != nil {
						glog.Error(err)
					}
				}
			}
			if json {
				err = utils.JSONify(diffResults)
				if err != nil {
					glog.Error(err)
				}
			}
			fmt.Println()
			glog.Info("Removing image file system directories from system")
			errMsg := remove(image1.FSPath, true)
			errMsg += remove(image2.FSPath, true)
			if errMsg != "" {
				glog.Error(errMsg)
			}
		} else {
			glog.Error(err.Error())
			os.Exit(1)
		}
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL