Merge pull request #8461 from Luap99/top-shell-completion

Implement shell completion for podman top
This commit is contained in:
OpenShift Merge Robot 2020-11-24 11:24:14 +01:00 committed by GitHub
commit 5267e73db0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 2 deletions

View File

@ -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) {

View File

@ -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

View File

@ -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