summaryrefslogtreecommitdiff
path: root/cmd/podman/pod_top.go
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-31 13:20:04 -0600
committerbaude <bbaude@redhat.com>2019-02-08 10:26:43 -0600
commit25a3923b61a5ca014318e6d957f68abd03947297 (patch)
tree2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/pod_top.go
parent962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff)
downloadpodman-25a3923b61a5ca014318e6d957f68abd03947297.tar.gz
podman-25a3923b61a5ca014318e6d957f68abd03947297.tar.bz2
podman-25a3923b61a5ca014318e6d957f68abd03947297.zip
Migrate to cobra CLI
We intend to migrate to the cobra cli from urfave/cli because the project is more well maintained. There are also some technical reasons as well which extend into our remote client work. Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/pod_top.go')
-rw-r--r--cmd/podman/pod_top.go55
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 {