From 318e95fd2a9a8b1bcd0f1caec4612335cc1ee591 Mon Sep 17 00:00:00 2001
From: Paul Holzinger <pholzing@redhat.com>
Date: Tue, 17 May 2022 16:14:59 +0200
Subject: shell completion: fix podman event --filter values

The completion suggested incorrect values for `podman events --filter
type=` . It should only list types not the event status. Also make sure
to use the constants instead of duplicating the strings.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
---
 cmd/podman/common/completion.go | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)

(limited to 'cmd')

diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index e07e28dab..1275d6cc0 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"
@@ -1091,11 +1092,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 +1114,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)
-- 
cgit v1.2.3-54-g00ecf