diff options
Diffstat (limited to 'cmd/podman/pod_top.go')
-rw-r--r-- | cmd/podman/pod_top.go | 55 |
1 files changed, 29 insertions, 26 deletions
diff --git a/cmd/podman/pod_top.go b/cmd/podman/pod_top.go index 1bd1287db..f1db2fac5 100644 --- a/cmd/podman/pod_top.go +++ b/cmd/podman/pod_top.go @@ -6,21 +6,17 @@ import ( "strings" "text/tabwriter" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/libpodruntime" "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( - podTopFlags = []cli.Flag{ - LatestFlag, - cli.BoolFlag{ - Name: "list-descriptors", - Hidden: true, - }, - } + podTopCommand cliconfig.PodTopValues + podTopDescription = fmt.Sprintf(`Display the running processes containers in a pod. Specify format descriptors to alter the output. You may run "podman pod top -l pid pcpu seccomp" to print the process ID, the CPU percentage and the seccomp mode of each process of @@ -28,24 +24,34 @@ the latest pod. %s `, getDescriptorString()) - podTopCommand = cli.Command{ - Name: "top", - Usage: "Display the running processes of containers in a pod", - Description: podTopDescription, - Flags: sortFlags(podTopFlags), - Action: podTopCmd, - ArgsUsage: "POD-NAME [format descriptors]", - SkipArgReorder: true, - OnUsageError: usageErrorHandler, + _podTopCommand = &cobra.Command{ + Use: "top", + Short: "Display the running processes of containers in a pod", + Long: podTopDescription, + RunE: func(cmd *cobra.Command, args []string) error { + podTopCommand.InputArgs = args + podTopCommand.GlobalFlags = MainGlobalOpts + return podTopCmd(&podTopCommand) + }, + Example: "POD-NAME [format descriptors]", } ) -func podTopCmd(c *cli.Context) error { +func init() { + podTopCommand.Command = _podTopCommand + flags := podTopCommand.Flags() + flags.BoolVarP(&podTopCommand.Latest, "latest,", "l", false, "Act on the latest pod podman is aware of") + flags.BoolVar(&podTopCommand.ListDescriptors, "list-descriptors", false, "") + flags.MarkHidden("list-descriptors") + +} + +func podTopCmd(c *cliconfig.PodTopValues) error { var pod *libpod.Pod var err error - args := c.Args() + args := c.InputArgs - if c.Bool("list-descriptors") { + if c.ListDescriptors { descriptors, err := libpod.GetContainerPidInformationDescriptors() if err != nil { return err @@ -54,21 +60,18 @@ func podTopCmd(c *cli.Context) error { return nil } - if len(args) < 1 && !c.Bool("latest") { + if len(args) < 1 && !c.Latest { return errors.Errorf("you must provide the name or id of a running pod") } - if err := validateFlags(c, podTopFlags); err != nil { - return err - } - runtime, err := libpodruntime.GetRuntime(c) + runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "error creating libpod runtime") } defer runtime.Shutdown(false) var descriptors []string - if c.Bool("latest") { + if c.Latest { descriptors = args pod, err = runtime.GetLatestPod() } else { |