V2 Fix --latest for podman diff commands

* --latest now forces container diff
* diff options now passed into domain layer
* updated help/usage messages

Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
Jhon Honce
2020-04-20 09:27:54 -07:00
parent e5e625b2a6
commit 3eac39aaa0
3 changed files with 21 additions and 11 deletions

View File

@ -45,7 +45,11 @@ func diff(cmd *cobra.Command, args []string) error {
return errors.New("container must be specified: podman container diff [options [...]] ID-NAME")
}
results, err := registry.ContainerEngine().ContainerDiff(registry.GetContext(), args[0], entities.DiffOptions{})
var id string
if len(args) > 0 {
id = args[0]
}
results, err := registry.ContainerEngine().ContainerDiff(registry.GetContext(), id, *diffOpts)
if err != nil {
return err
}

View File

@ -46,10 +46,9 @@ func init() {
}
func diff(cmd *cobra.Command, args []string) error {
if found, err := registry.ImageEngine().Exists(registry.GetContext(), args[0]); err != nil {
return err
} else if found.Value {
return images.Diff(cmd, args, diffOpts)
// Latest implies looking for a container
if diffOpts.Latest {
return containers.Diff(cmd, args, diffOpts)
}
if found, err := registry.ContainerEngine().ContainerExists(registry.GetContext(), args[0]); err != nil {
@ -57,5 +56,12 @@ func diff(cmd *cobra.Command, args []string) error {
} else if found.Value {
return containers.Diff(cmd, args, diffOpts)
}
if found, err := registry.ImageEngine().Exists(registry.GetContext(), args[0]); err != nil {
return err
} else if found.Value {
return images.Diff(cmd, args, diffOpts)
}
return fmt.Errorf("%s not found on system", args[0])
}

View File

@ -11,8 +11,8 @@ import (
var (
// podman container _inspect_
diffCmd = &cobra.Command{
Use: "diff [flags] CONTAINER",
Args: registry.IdOrLatestArgs,
Use: "diff [flags] IMAGE",
Args: cobra.ExactArgs(1),
Short: "Inspect changes on image's file systems",
Long: `Displays changes on a image's filesystem. The image will be compared to its parent layer.`,
RunE: diff,
@ -32,16 +32,16 @@ func init() {
diffOpts = &entities.DiffOptions{}
flags := diffCmd.Flags()
flags.BoolVar(&diffOpts.Archive, "archive", true, "Save the diff as a tar archive")
_ = flags.MarkHidden("archive")
_ = flags.MarkDeprecated("archive", "Provided for backwards compatibility, has no impact on output.")
flags.StringVar(&diffOpts.Format, "format", "", "Change the output format")
}
func diff(cmd *cobra.Command, args []string) error {
if len(args) == 0 && !diffOpts.Latest {
return errors.New("image must be specified: podman image diff [options [...]] ID-NAME")
if diffOpts.Latest {
return errors.New("image diff does not support --latest")
}
results, err := registry.ImageEngine().Diff(registry.GetContext(), args[0], entities.DiffOptions{})
results, err := registry.ImageEngine().Diff(registry.GetContext(), args[0], *diffOpts)
if err != nil {
return err
}