diff options
-rw-r--r-- | cmd/podman/common/completion.go | 3 | ||||
-rw-r--r-- | cmd/podman/common/inspect.go | 16 | ||||
-rw-r--r-- | cmd/podman/containers/inspect.go | 2 | ||||
-rw-r--r-- | cmd/podman/images/inspect.go | 2 | ||||
-rw-r--r-- | cmd/podman/inspect/inspect.go | 51 | ||||
-rw-r--r-- | cmd/podman/networks/inspect.go | 2 | ||||
-rw-r--r-- | cmd/podman/volumes/export.go | 3 | ||||
-rw-r--r-- | cmd/podman/volumes/import.go | 3 | ||||
-rw-r--r-- | cmd/podman/volumes/inspect.go | 2 |
9 files changed, 42 insertions, 42 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go index 1275d6cc0..f207f6925 100644 --- a/cmd/podman/common/completion.go +++ b/cmd/podman/common/completion.go @@ -1141,9 +1141,8 @@ func AutocompleteImageSort(cmd *cobra.Command, args []string, toComplete string) } // AutocompleteInspectType - Autocomplete inspect type options. -// -> "container", "image", "all" func AutocompleteInspectType(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { - types := []string{"container", "image", "all"} + types := []string{AllType, ContainerType, ImageType, NetworkType, PodType, VolumeType} return types, cobra.ShellCompDirectiveNoFileComp } diff --git a/cmd/podman/common/inspect.go b/cmd/podman/common/inspect.go new file mode 100644 index 000000000..12a5af5a9 --- /dev/null +++ b/cmd/podman/common/inspect.go @@ -0,0 +1,16 @@ +package common + +const ( + // AllType can be of type ImageType or ContainerType. + AllType = "all" + // ContainerType is the container type. + ContainerType = "container" + // ImageType is the image type. + ImageType = "image" + // NetworkType is the network type + NetworkType = "network" + // PodType is the pod type. + PodType = "pod" + // VolumeType is the volume type + VolumeType = "volume" +) diff --git a/cmd/podman/containers/inspect.go b/cmd/podman/containers/inspect.go index 03e6411a1..4195cf020 100644 --- a/cmd/podman/containers/inspect.go +++ b/cmd/podman/containers/inspect.go @@ -42,6 +42,6 @@ func init() { func inspectExec(cmd *cobra.Command, args []string) error { // Force container type - inspectOpts.Type = inspect.ContainerType + inspectOpts.Type = common.ContainerType return inspect.Inspect(args, *inspectOpts) } diff --git a/cmd/podman/images/inspect.go b/cmd/podman/images/inspect.go index 22c404b3f..310f8cda8 100644 --- a/cmd/podman/images/inspect.go +++ b/cmd/podman/images/inspect.go @@ -38,6 +38,6 @@ func init() { } func inspectExec(cmd *cobra.Command, args []string) error { - inspectOpts.Type = inspect.ImageType + inspectOpts.Type = common.ImageType return inspect.Inspect(args, *inspectOpts) } diff --git a/cmd/podman/inspect/inspect.go b/cmd/podman/inspect/inspect.go index b26b2d667..f6e3fca06 100644 --- a/cmd/podman/inspect/inspect.go +++ b/cmd/podman/inspect/inspect.go @@ -21,21 +21,6 @@ import ( "github.com/spf13/cobra" ) -const ( - // AllType can be of type ImageType or ContainerType. - AllType = "all" - // ContainerType is the container type. - ContainerType = "container" - // ImageType is the image type. - ImageType = "image" - // NetworkType is the network type - NetworkType = "network" - // PodType is the pod type. - PodType = "pod" - // VolumeType is the volume type - VolumeType = "volume" -) - // AddInspectFlagSet takes a command and adds the inspect flags and returns an // InspectOptions object. func AddInspectFlagSet(cmd *cobra.Command) *entities.InspectOptions { @@ -49,7 +34,7 @@ func AddInspectFlagSet(cmd *cobra.Command) *entities.InspectOptions { _ = cmd.RegisterFlagCompletionFunc(formatFlagName, completion.AutocompleteNone) typeFlagName := "type" - flags.StringVarP(&opts.Type, typeFlagName, "t", AllType, fmt.Sprintf("Specify inspect-object type (%q, %q or %q)", ImageType, ContainerType, AllType)) + flags.StringVarP(&opts.Type, typeFlagName, "t", common.AllType, "Specify inspect-object type") _ = cmd.RegisterFlagCompletionFunc(typeFlagName, common.AutocompleteInspectType) validate.AddLatestFlag(cmd, &opts.Latest) @@ -76,21 +61,22 @@ type inspector struct { // newInspector creates a new inspector based on the specified options. func newInspector(options entities.InspectOptions) (*inspector, error) { switch options.Type { - case ImageType, ContainerType, AllType, PodType, NetworkType, VolumeType: + case common.ImageType, common.ContainerType, common.AllType, common.PodType, common.NetworkType, common.VolumeType: // Valid types. default: - return nil, errors.Errorf("invalid type %q: must be %q, %q, %q, %q, %q, or %q", options.Type, ImageType, ContainerType, PodType, NetworkType, VolumeType, AllType) + return nil, errors.Errorf("invalid type %q: must be %q, %q, %q, %q, %q, or %q", options.Type, + common.ImageType, common.ContainerType, common.PodType, common.NetworkType, common.VolumeType, common.AllType) } - if options.Type == ImageType { + if options.Type == common.ImageType { if options.Latest { - return nil, errors.Errorf("latest is not supported for type %q", ImageType) + return nil, errors.Errorf("latest is not supported for type %q", common.ImageType) } if options.Size { - return nil, errors.Errorf("size is not supported for type %q", ImageType) + return nil, errors.Errorf("size is not supported for type %q", common.ImageType) } } - if options.Type == PodType && options.Size { - return nil, errors.Errorf("size is not supported for type %q", PodType) + if options.Type == common.PodType && options.Size { + return nil, errors.Errorf("size is not supported for type %q", common.PodType) } podOpts := entities.PodInspectOptions{ Latest: options.Latest, @@ -122,21 +108,21 @@ func (i *inspector) inspect(namesOrIDs []string) error { if len(namesOrIDs) > 0 { return errors.New("--latest and arguments cannot be used together") } - if i.options.Type == AllType { - tmpType = ContainerType // -l works with --type=all, defaults to containertype + if i.options.Type == common.AllType { + tmpType = common.ContainerType // -l works with --type=all, defaults to containertype } } // Inspect - note that AllType requires us to expensively query one-by-one. switch tmpType { - case AllType: + case common.AllType: allData, allErrs, err := i.inspectAll(ctx, namesOrIDs) if err != nil { return err } data = allData errs = allErrs - case ImageType: + case common.ImageType: imgData, allErrs, err := i.imageEngine.Inspect(ctx, namesOrIDs, i.options) if err != nil { return err @@ -145,7 +131,7 @@ func (i *inspector) inspect(namesOrIDs []string) error { for i := range imgData { data = append(data, imgData[i]) } - case ContainerType: + case common.ContainerType: ctrData, allErrs, err := i.containerEngine.ContainerInspect(ctx, namesOrIDs, i.options) if err != nil { return err @@ -154,7 +140,7 @@ func (i *inspector) inspect(namesOrIDs []string) error { for i := range ctrData { data = append(data, ctrData[i]) } - case PodType: + case common.PodType: for _, pod := range namesOrIDs { i.podOptions.NameOrID = pod podData, err := i.containerEngine.PodInspect(ctx, i.podOptions) @@ -184,7 +170,7 @@ func (i *inspector) inspect(namesOrIDs []string) error { data = append(data, podData) } } - case NetworkType: + case common.NetworkType: networkData, allErrs, err := registry.ContainerEngine().NetworkInspect(ctx, namesOrIDs, i.options) if err != nil { return err @@ -193,7 +179,7 @@ func (i *inspector) inspect(namesOrIDs []string) error { for i := range networkData { data = append(data, networkData[i]) } - case VolumeType: + case common.VolumeType: volumeData, allErrs, err := i.containerEngine.VolumeInspect(ctx, namesOrIDs, i.options) if err != nil { return err @@ -203,7 +189,8 @@ func (i *inspector) inspect(namesOrIDs []string) error { data = append(data, volumeData[i]) } default: - return errors.Errorf("invalid type %q: must be %q, %q, %q, %q, %q, or %q", i.options.Type, ImageType, ContainerType, PodType, NetworkType, VolumeType, AllType) + return errors.Errorf("invalid type %q: must be %q, %q, %q, %q, %q, or %q", i.options.Type, + common.ImageType, common.ContainerType, common.PodType, common.NetworkType, common.VolumeType, common.AllType) } // Always print an empty array if data == nil { diff --git a/cmd/podman/networks/inspect.go b/cmd/podman/networks/inspect.go index 8f39ec395..1a8444147 100644 --- a/cmd/podman/networks/inspect.go +++ b/cmd/podman/networks/inspect.go @@ -37,6 +37,6 @@ func init() { } func networkInspect(_ *cobra.Command, args []string) error { - inspectOpts.Type = inspect.NetworkType + inspectOpts.Type = common.NetworkType return inspect.Inspect(args, *inspectOpts) } diff --git a/cmd/podman/volumes/export.go b/cmd/podman/volumes/export.go index 1011604de..5086323f9 100644 --- a/cmd/podman/volumes/export.go +++ b/cmd/podman/volumes/export.go @@ -6,7 +6,6 @@ import ( "github.com/containers/common/pkg/completion" "github.com/containers/podman/v4/cmd/podman/common" - "github.com/containers/podman/v4/cmd/podman/inspect" "github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/utils" @@ -58,7 +57,7 @@ func export(cmd *cobra.Command, args []string) error { if cliExportOpts.Output == "" { return errors.New("expects output path, use --output=[path]") } - inspectOpts.Type = inspect.VolumeType + inspectOpts.Type = common.VolumeType volumeData, _, err := containerEngine.VolumeInspect(ctx, args, inspectOpts) if err != nil { return err diff --git a/cmd/podman/volumes/import.go b/cmd/podman/volumes/import.go index 9ff17e5b1..988c5536d 100644 --- a/cmd/podman/volumes/import.go +++ b/cmd/podman/volumes/import.go @@ -5,7 +5,6 @@ import ( "os" "github.com/containers/podman/v4/cmd/podman/common" - "github.com/containers/podman/v4/cmd/podman/inspect" "github.com/containers/podman/v4/cmd/podman/parse" "github.com/containers/podman/v4/cmd/podman/registry" "github.com/containers/podman/v4/pkg/domain/entities" @@ -60,7 +59,7 @@ func importVol(cmd *cobra.Command, args []string) error { tarFile = os.Stdin } - inspectOpts.Type = inspect.VolumeType + inspectOpts.Type = common.VolumeType volumeData, _, err := containerEngine.VolumeInspect(ctx, volumes, inspectOpts) if err != nil { return err diff --git a/cmd/podman/volumes/inspect.go b/cmd/podman/volumes/inspect.go index f21f9c233..7cf363f36 100644 --- a/cmd/podman/volumes/inspect.go +++ b/cmd/podman/volumes/inspect.go @@ -48,6 +48,6 @@ func volumeInspect(cmd *cobra.Command, args []string) error { if (inspectOpts.All && len(args) > 0) || (!inspectOpts.All && len(args) < 1) { return errors.New("provide one or more volume names or use --all") } - inspectOpts.Type = inspect.VolumeType + inspectOpts.Type = common.VolumeType return inspect.Inspect(args, *inspectOpts) } |