Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 0b210d2

Browse files
author
Priya Wadhwa
committed
Diff between layers
1 parent e4a55a7 commit 0b210d2

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

cmd/diff.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ import (
3131
)
3232

3333
var filename string
34+
var layers bool
3435

3536
var diffCmd = &cobra.Command{
3637
Use: "diff",
3738
Short: "Compare two images: [image1] [image2]",
3839
Long: `Compares two images using the specifed analyzers as indicated via flags (see documentation for available ones).`,
3940
Args: func(cmd *cobra.Command, args []string) error {
40-
if err := validateArgs(args, checkDiffArgNum, checkIfValidAnalyzer, checkFilenameFlag); err != nil {
41+
if err := validateArgs(args, checkDiffArgNum, checkIfValidAnalyzer, checkFilenameFlag, checkLayersFlag); err != nil {
4142
return err
4243
}
4344
return nil
@@ -69,6 +70,18 @@ func checkFilenameFlag(_ []string) error {
6970
return errors.New("Please include --types=file with the --filename flag")
7071
}
7172

73+
func checkLayersFlag(_ []string) error {
74+
if layers {
75+
for _, t := range types {
76+
if t == "file" {
77+
return nil
78+
}
79+
}
80+
return errors.New("Please include --types=file with the --layers flag")
81+
}
82+
return nil
83+
}
84+
7285
func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
7386
diffTypes, err := differs.GetAnalyzers(diffArgs)
7487
if err != nil {
@@ -102,6 +115,12 @@ func diffImages(image1Arg, image2Arg string, diffArgs []string) error {
102115
defer pkgutil.CleanupImage(*imageMap[image2Arg])
103116
}
104117

118+
if layers {
119+
if err := diffLayers(imageMap[image1Arg], imageMap[image2Arg]); err != nil {
120+
return err
121+
}
122+
}
123+
105124
output.PrintToStdErr("Computing diffs\n")
106125
req := differs.DiffRequest{
107126
Image1: *imageMap[image1Arg],
@@ -139,6 +158,7 @@ func diffFile(image1, image2 *pkgutil.Image) error {
139158

140159
func init() {
141160
diffCmd.Flags().StringVarP(&filename, "filename", "f", "", "Set this flag to the path of a file in both containers to view the diff of the file. Must be used with --types=file flag.")
161+
diffCmd.Flags().BoolVarP(&layers, "layers", "", false, "Set this flag to diff the filesystems of two images by layer. Must be used with --types=file flag.")
142162
RootCmd.AddCommand(diffCmd)
143163
addSharedFlags(diffCmd)
144164
output.AddFlags(diffCmd)

0 commit comments

Comments
 (0)