github.com/hanks177/podman/v4@v4.1.3-0.20220613032544-16d90015bc83/cmd/podman/diff.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/hanks177/podman/v4/cmd/podman/common"
     5  	"github.com/hanks177/podman/v4/cmd/podman/diff"
     6  	"github.com/hanks177/podman/v4/cmd/podman/registry"
     7  	"github.com/hanks177/podman/v4/cmd/podman/validate"
     8  	"github.com/hanks177/podman/v4/libpod/define"
     9  	"github.com/hanks177/podman/v4/pkg/domain/entities"
    10  	"github.com/spf13/cobra"
    11  )
    12  
    13  // Inspect is one of the outlier commands in that it operates on images/containers/...
    14  
    15  var (
    16  	// Command: podman _diff_ Object_ID
    17  	diffDescription = `Displays changes on a container or image's filesystem.  The container or image will be compared to its parent layer or the second argument when given.`
    18  	diffCmd         = &cobra.Command{
    19  		Use:               "diff [options] {CONTAINER|IMAGE} [{CONTAINER|IMAGE}]",
    20  		Args:              diff.ValidateContainerDiffArgs,
    21  		Short:             "Display the changes to the object's file system",
    22  		Long:              diffDescription,
    23  		RunE:              diffRun,
    24  		ValidArgsFunction: common.AutocompleteContainersAndImages,
    25  		Example: `podman diff imageID
    26    podman diff ctrID
    27    podman diff --format json redis:alpine`,
    28  	}
    29  
    30  	diffOpts = entities.DiffOptions{}
    31  )
    32  
    33  func init() {
    34  	registry.Commands = append(registry.Commands, registry.CliCommand{
    35  		Command: diffCmd,
    36  	})
    37  	flags := diffCmd.Flags()
    38  
    39  	formatFlagName := "format"
    40  	flags.StringVar(&diffOpts.Format, formatFlagName, "", "Change the output format (json)")
    41  	_ = diffCmd.RegisterFlagCompletionFunc(formatFlagName, common.AutocompleteFormat(nil))
    42  
    43  	validate.AddLatestFlag(diffCmd, &diffOpts.Latest)
    44  }
    45  
    46  func diffRun(cmd *cobra.Command, args []string) error {
    47  	diffOpts.Type = define.DiffAll
    48  	return diff.Diff(cmd, args, diffOpts)
    49  }