diff options
author | Paul Holzinger <paul.holzinger@web.de> | 2020-11-23 23:32:48 +0100 |
---|---|---|
committer | Paul Holzinger <paul.holzinger@web.de> | 2020-11-23 23:45:33 +0100 |
commit | f38e18959974901eec4b69bc904de910a4459da9 (patch) | |
tree | 75f0c7bb1ca5f642c6b023d3aeef3df729c8631d /cmd | |
parent | cd6c4cb0affdb1e8a647079b2808da6bf833d543 (diff) | |
download | podman-f38e18959974901eec4b69bc904de910a4459da9.tar.gz podman-f38e18959974901eec4b69bc904de910a4459da9.tar.bz2 podman-f38e18959974901eec4b69bc904de910a4459da9.zip |
Implement shell completion for podman top
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/podman/common/completion.go | 20 | ||||
-rw-r--r-- | cmd/podman/containers/top.go | 2 | ||||
-rw-r--r-- | cmd/podman/pods/top.go | 2 |
3 files changed, 22 insertions, 2 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) { diff --git a/cmd/podman/containers/top.go b/cmd/podman/containers/top.go index f00b1dce1..e691f527a 100644 --- a/cmd/podman/containers/top.go +++ b/cmd/podman/containers/top.go @@ -30,7 +30,7 @@ var ( Long: topDescription, RunE: top, Args: cobra.ArbitraryArgs, - ValidArgsFunction: common.AutocompleteContainersRunning, + ValidArgsFunction: common.AutocompleteTopCmd, Example: `podman top ctrID podman top --latest podman top ctrID pid seccomp args %C diff --git a/cmd/podman/pods/top.go b/cmd/podman/pods/top.go index 45ef1e7c2..829882080 100644 --- a/cmd/podman/pods/top.go +++ b/cmd/podman/pods/top.go @@ -29,7 +29,7 @@ var ( Long: topDescription, RunE: top, Args: cobra.ArbitraryArgs, - ValidArgsFunction: common.AutocompletePodsRunning, + ValidArgsFunction: common.AutocompleteTopCmd, Example: `podman pod top podID podman pod top --latest podman pod top podID pid seccomp args %C |