aboutsummaryrefslogtreecommitdiff
path: root/cmd/podman/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/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/top.go')
-rw-r--r--cmd/podman/top.go55
1 files changed, 29 insertions, 26 deletions
diff --git a/cmd/podman/top.go b/cmd/podman/top.go
index 3012265ea..a03830ee5 100644
--- a/cmd/podman/top.go
+++ b/cmd/podman/top.go
@@ -6,11 +6,12 @@ import (
"strings"
"text/tabwriter"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
func getDescriptorString() string {
@@ -24,13 +25,7 @@ Format Descriptors:
}
var (
- topFlags = []cli.Flag{
- LatestFlag,
- cli.BoolFlag{
- Name: "list-descriptors",
- Hidden: true,
- },
- }
+ topCommand cliconfig.TopValues
topDescription = fmt.Sprintf(`Display the running processes of the container. Specify format descriptors
to alter the output. You may run "podman top -l pid pcpu seccomp" to print
the process ID, the CPU percentage and the seccomp mode of each process of
@@ -38,24 +33,35 @@ the latest container.
%s
`, getDescriptorString())
- topCommand = cli.Command{
- Name: "top",
- Usage: "Display the running processes of a container",
- Description: topDescription,
- Flags: sortFlags(topFlags),
- Action: topCmd,
- ArgsUsage: "CONTAINER-NAME [format descriptors]",
- SkipArgReorder: true,
- OnUsageError: usageErrorHandler,
+ _topCommand = &cobra.Command{
+ Use: "top",
+ Short: "Display the running processes of a container",
+ Long: topDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ topCommand.InputArgs = args
+ topCommand.GlobalFlags = MainGlobalOpts
+ return topCmd(&topCommand)
+ },
+ Example: "CONTAINER-NAME [format descriptors]",
}
)
-func topCmd(c *cli.Context) error {
+func init() {
+ topCommand.Command = _topCommand
+ flags := topCommand.Flags()
+ flags.BoolVar(&topCommand.ListDescriptors, "list-descriptors", false, "")
+ flags.MarkHidden("list-descriptors")
+ flags.BoolVarP(&topCommand.Latest, "latest", "l", false, "Act on the latest container podman is aware of")
+
+ rootCmd.AddCommand(topCommand.Command)
+}
+
+func topCmd(c *cliconfig.TopValues) error {
var container *libpod.Container
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
@@ -64,22 +70,19 @@ func topCmd(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 container")
}
- if err := validateFlags(c, topFlags); err != nil {
- return err
- }
rootless.SetSkipStorageSetup(true)
- 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
container, err = runtime.GetLatestContainer()
} else {