summaryrefslogtreecommitdiff
path: root/cmd/podman/history.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/history.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/history.go')
-rw-r--r--cmd/podman/history.go68
1 files changed, 30 insertions, 38 deletions
diff --git a/cmd/podman/history.go b/cmd/podman/history.go
index 8a9b6cd94..97e501947 100644
--- a/cmd/podman/history.go
+++ b/cmd/podman/history.go
@@ -6,12 +6,13 @@ import (
"strings"
"time"
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/libpod/adapter"
"github.com/containers/libpod/libpod/image"
"github.com/docker/go-units"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
const createdByTruncLength = 45
@@ -34,53 +35,44 @@ type historyOptions struct {
}
var (
- historyFlags = []cli.Flag{
- cli.BoolTFlag{
- Name: "human, H",
- Usage: "Display sizes and dates in human readable format",
- },
- cli.BoolFlag{
- Name: "no-trunc, notruncate",
- Usage: "Do not truncate the output",
- },
- cli.BoolFlag{
- Name: "quiet, q",
- Usage: "Display the numeric IDs only",
- },
- cli.StringFlag{
- Name: "format",
- Usage: "Change the output to JSON or a Go template",
- },
- }
+ historyCommand cliconfig.HistoryValues
historyDescription = "Displays the history of an image. The information can be printed out in an easy to read, " +
"or user specified format, and can be truncated."
- historyCommand = cli.Command{
- Name: "history",
- Usage: "Show history of a specified image",
- Description: historyDescription,
- Flags: sortFlags(historyFlags),
- Action: historyCmd,
- ArgsUsage: "",
- UseShortOptionHandling: true,
- OnUsageError: usageErrorHandler,
+ _historyCommand = &cobra.Command{
+ Use: "history",
+ Short: "Show history of a specified image",
+ Long: historyDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ historyCommand.InputArgs = args
+ historyCommand.GlobalFlags = MainGlobalOpts
+ return historyCmd(&historyCommand)
+ },
}
)
-func historyCmd(c *cli.Context) error {
- if err := validateFlags(c, historyFlags); err != nil {
- return err
- }
+func init() {
+ historyCommand.Command = _historyCommand
+ flags := historyCommand.Flags()
+ flags.StringVar(&historyCommand.Format, "format", "", "Change the output to JSON or a Go template")
+ flags.BoolVarP(&historyCommand.Human, "human", "H", true, "Display sizes and dates in human readable format")
+ // notrucate needs to be added
+ flags.BoolVar(&historyCommand.NoTrunc, "no-trunc", false, "Do not truncate the output")
+ flags.BoolVarP(&historyCommand.Quiet, "quiet", "q", false, "Display the numeric IDs only")
- runtime, err := adapter.GetRuntime(c)
+ rootCmd.AddCommand(historyCommand.Command)
+
+}
+func historyCmd(c *cliconfig.HistoryValues) error {
+ runtime, err := adapter.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- format := genHistoryFormat(c.String("format"), c.Bool("quiet"))
+ format := genHistoryFormat(c.Format, c.Quiet)
- args := c.Args()
+ args := c.InputArgs
if len(args) == 0 {
return errors.Errorf("an image name must be specified")
}
@@ -93,9 +85,9 @@ func historyCmd(c *cli.Context) error {
return err
}
opts := historyOptions{
- human: c.BoolT("human"),
- noTrunc: c.Bool("no-trunc"),
- quiet: c.Bool("quiet"),
+ human: c.Human,
+ noTrunc: c.NoTrunc,
+ quiet: c.Quiet,
format: format,
}