summaryrefslogtreecommitdiff
path: root/cmd/podman/common
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-11-24 11:24:14 +0100
committerGitHub <noreply@github.com>2020-11-24 11:24:14 +0100
commit5267e73db0814a6af9704aae62d600b08df80774 (patch)
tree1f521c9b5844467db383c143ac14bca5696f670a /cmd/podman/common
parent4fe7c3f7bc8a1d20a23e87783b6a17b887c782e1 (diff)
parentf38e18959974901eec4b69bc904de910a4459da9 (diff)
downloadpodman-5267e73db0814a6af9704aae62d600b08df80774.tar.gz
podman-5267e73db0814a6af9704aae62d600b08df80774.tar.bz2
podman-5267e73db0814a6af9704aae62d600b08df80774.zip
Merge pull request #8461 from Luap99/top-shell-completion
Implement shell completion for podman top
Diffstat (limited to 'cmd/podman/common')
-rw-r--r--cmd/podman/common/completion.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/cmd/podman/common/completion.go b/cmd/podman/common/completion.go
index 6723cbf62..9856e46ef 100644
--- a/cmd/podman/common/completion.go
+++ b/cmd/podman/common/completion.go
@@ -14,6 +14,7 @@ import (
"github.com/containers/podman/v2/pkg/registries"
"github.com/containers/podman/v2/pkg/rootless"
systemdGen "github.com/containers/podman/v2/pkg/systemd/generate"
+ "github.com/containers/podman/v2/pkg/util"
"github.com/spf13/cobra"
)
@@ -476,6 +477,25 @@ func AutocompleteNetworkConnectCmd(cmd *cobra.Command, args []string, toComplete
return nil, cobra.ShellCompDirectiveNoFileComp
}
+// AutocompleteTopCmd - Autocomplete podman top/pod top command args.
+func AutocompleteTopCmd(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
+ latest := cmd.Flags().Lookup("latest")
+ // only complete containers/pods as first arg if latest is not set
+ if len(args) == 0 && (latest == nil || !latest.Changed) {
+ if cmd.Parent().Name() == "pod" {
+ // need to complete pods since we are using pod top
+ return getPods(cmd, toComplete, completeDefault)
+ }
+ return getContainers(cmd, toComplete, completeDefault)
+ }
+ descriptors, err := util.GetContainerPidInformationDescriptors()
+ if err != nil {
+ cobra.CompErrorln(err.Error())
+ return nil, cobra.ShellCompDirectiveNoFileComp
+ }
+ return descriptors, cobra.ShellCompDirectiveNoFileComp
+}
+
// AutocompleteSystemConnections - Autocomplete system connections.
func AutocompleteSystemConnections(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if !validCurrentCmdLine(cmd, args, toComplete) {