summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2022-05-19 18:45:03 -0400
committerGitHub <noreply@github.com>2022-05-19 18:45:03 -0400
commit1916fe22a932183e0847e9f7b087f6ece4d7c48c (patch)
tree49a030b80ad533a4befae84274e9a72dd99ad639 /cmd/podman/common
parent913caaa9b1de2b63692c9bae15120208194c9eb3 (diff)
parent9c9fc96d2756ba6ff1ef3a2e8301992d4b5ab189 (diff)
downloadpodman-1916fe22a932183e0847e9f7b087f6ece4d7c48c.tar.gz
podman-1916fe22a932183e0847e9f7b087f6ece4d7c48c.tar.bz2
podman-1916fe22a932183e0847e9f7b087f6ece4d7c48c.zip
Merge pull request #14272 from Luap99/completion2
shell completion: use more constants in the code
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/completion.go38
-rw-r--r--cmd/podman/common/inspect.go16
2 files changed, 40 insertions, 14 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index e07e28dab..58dff3578 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -12,6 +12,7 @@ import (
"github.com/containers/image/v5/pkg/sysregistriesv2"
"github.com/containers/podman/v4/cmd/podman/registry"
"github.com/containers/podman/v4/libpod/define"
+ "github.com/containers/podman/v4/libpod/events"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/rootless"
systemdDefine "github.com/containers/podman/v4/pkg/systemd/define"
@@ -24,6 +25,8 @@ var (
ChangeCmds = []string{"CMD", "ENTRYPOINT", "ENV", "EXPOSE", "LABEL", "ONBUILD", "STOPSIGNAL", "USER", "VOLUME", "WORKDIR"}
// LogLevels supported by podman
LogLevels = []string{"trace", "debug", "info", "warn", "warning", "error", "fatal", "panic"}
+ // ValidSaveFormats is the list of support podman save formats
+ ValidSaveFormats = []string{define.OCIManifestDir, define.OCIArchive, define.V2s2ManifestDir, define.V2s2Archive}
)
type completeType int
@@ -1091,11 +1094,21 @@ func getMethodNames(f reflect.Value, prefix string) []string {
// AutocompleteEventFilter - Autocomplete event filter flag options.
// -> "container=", "event=", "image=", "pod=", "volume=", "type="
func AutocompleteEventFilter(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ event := func(_ string) ([]string, cobra.ShellCompDirective) {
+ return []string{events.Attach.String(), events.AutoUpdate.String(), events.Checkpoint.String(), events.Cleanup.String(),
+ events.Commit.String(), events.Create.String(), events.Exec.String(), events.ExecDied.String(),
+ events.Exited.String(), events.Export.String(), events.Import.String(), events.Init.String(), events.Kill.String(),
+ events.LoadFromArchive.String(), events.Mount.String(), events.NetworkConnect.String(),
+ events.NetworkDisconnect.String(), events.Pause.String(), events.Prune.String(), events.Pull.String(),
+ events.Push.String(), events.Refresh.String(), events.Remove.String(), events.Rename.String(),
+ events.Renumber.String(), events.Restart.String(), events.Restore.String(), events.Save.String(),
+ events.Start.String(), events.Stop.String(), events.Sync.String(), events.Tag.String(), events.Unmount.String(),
+ events.Unpause.String(), events.Untag.String(),
+ }, cobra.ShellCompDirectiveNoFileComp
+ }
eventTypes := func(_ string) ([]string, cobra.ShellCompDirective) {
- return []string{"attach", "checkpoint", "cleanup", "commit", "connect", "create", "disconnect", "exec",
- "exec_died", "exited", "export", "import", "init", "kill", "loadFromArchive", "mount", "pause",
- "prune", "pull", "push", "refresh", "remove", "rename", "renumber", "restart", "restore", "save",
- "start", "stop", "sync", "tag", "unmount", "unpause", "untag",
+ return []string{events.Container.String(), events.Image.String(), events.Network.String(),
+ events.Pod.String(), events.System.String(), events.Volume.String(),
}, cobra.ShellCompDirectiveNoFileComp
}
kv := keyValueCompletion{
@@ -1103,7 +1116,7 @@ func AutocompleteEventFilter(cmd *cobra.Command, args []string, toComplete strin
"image=": func(s string) ([]string, cobra.ShellCompDirective) { return getImages(cmd, s) },
"pod=": func(s string) ([]string, cobra.ShellCompDirective) { return getPods(cmd, s, completeDefault) },
"volume=": func(s string) ([]string, cobra.ShellCompDirective) { return getVolumes(cmd, s) },
- "event=": eventTypes,
+ "event=": event,
"type=": eventTypes,
}
return completeKeyValues(toComplete, kv)
@@ -1130,9 +1143,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
}
@@ -1182,10 +1194,8 @@ func AutocompletePsSort(cmd *cobra.Command, args []string, toComplete string) ([
}
// AutocompleteImageSaveFormat - Autocomplete image save format options.
-// -> "oci-archive", "oci-dir", "docker-dir"
func AutocompleteImageSaveFormat(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- formats := []string{"oci-archive", "oci-dir", "docker-dir"}
- return formats, cobra.ShellCompDirectiveNoFileComp
+ return ValidSaveFormats, cobra.ShellCompDirectiveNoFileComp
}
// AutocompleteWaitCondition - Autocomplete wait condition options.
@@ -1198,21 +1208,21 @@ func AutocompleteWaitCondition(cmd *cobra.Command, args []string, toComplete str
// AutocompleteCgroupManager - Autocomplete cgroup manager options.
// -> "cgroupfs", "systemd"
func AutocompleteCgroupManager(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- types := []string{"cgroupfs", "systemd"}
+ types := []string{config.CgroupfsCgroupsManager, config.SystemdCgroupsManager}
return types, cobra.ShellCompDirectiveNoFileComp
}
// AutocompleteEventBackend - Autocomplete event backend options.
// -> "file", "journald", "none"
func AutocompleteEventBackend(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- types := []string{"file", "journald", "none"}
+ types := []string{events.LogFile.String(), events.Journald.String(), events.Null.String()}
return types, cobra.ShellCompDirectiveNoFileComp
}
// AutocompleteNetworkBackend - Autocomplete network backend options.
// -> "cni", "netavark"
func AutocompleteNetworkBackend(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- types := []string{"cni", "netavark"}
+ types := []string{string(types.CNI), string(types.Netavark)}
return types, cobra.ShellCompDirectiveNoFileComp
}
@@ -1225,7 +1235,7 @@ func AutocompleteLogLevel(cmd *cobra.Command, args []string, toComplete string)
// AutocompleteSDNotify - Autocomplete sdnotify options.
// -> "container", "conmon", "ignore"
func AutocompleteSDNotify(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
- types := []string{"container", "conmon", "ignore"}
+ types := []string{define.SdNotifyModeContainer, define.SdNotifyModeContainer, define.SdNotifyModeIgnore}
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"
+)