diff options
author | baude <bbaude@redhat.com> | 2019-01-31 13:20:04 -0600 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-02-08 10:26:43 -0600 |
commit | 25a3923b61a5ca014318e6d957f68abd03947297 (patch) | |
tree | 2ccb4a0bd9bda70c1c258dcb1b8aca8961d9ad30 /cmd/podman/info.go | |
parent | 962850c6e0dfcee926af31fc0ad24f1f6c26f8ac (diff) | |
download | podman-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/info.go')
-rw-r--r-- | cmd/podman/info.go | 56 |
1 files changed, 29 insertions, 27 deletions
diff --git a/cmd/podman/info.go b/cmd/podman/info.go index 19078cea5..0896e16a4 100644 --- a/cmd/podman/info.go +++ b/cmd/podman/info.go @@ -4,45 +4,47 @@ import ( "fmt" rt "runtime" + "github.com/containers/libpod/cmd/podman/cliconfig" "github.com/containers/libpod/cmd/podman/formats" "github.com/containers/libpod/libpod" "github.com/containers/libpod/libpod/adapter" "github.com/containers/libpod/version" "github.com/pkg/errors" - "github.com/urfave/cli" + "github.com/spf13/cobra" ) var ( + infoCommand cliconfig.InfoValues + infoDescription = "Display podman system information" - infoCommand = cli.Command{ - Name: "info", - Usage: infoDescription, - Description: `Information display here pertain to the host, current storage stats, and build of podman. Useful for the user and when reporting issues.`, - Flags: sortFlags(infoFlags), - Action: infoCmd, - ArgsUsage: "", - OnUsageError: usageErrorHandler, - } - infoFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "debug, D", - Usage: "Display additional debug information", - }, - cli.StringFlag{ - Name: "format, f", - Usage: "Change the output format to JSON or a Go template", + _infoCommand = &cobra.Command{ + Use: "info", + Long: infoDescription, + Short: `Display information pertaining to the host, current storage stats, and build of podman. Useful for the user and when reporting issues.`, + RunE: func(cmd *cobra.Command, args []string) error { + infoCommand.InputArgs = args + infoCommand.GlobalFlags = MainGlobalOpts + return infoCmd(&infoCommand) }, + Example: "", } ) -func infoCmd(c *cli.Context) error { - if err := validateFlags(c, infoFlags); err != nil { - return err - } +func init() { + infoCommand.Command = _infoCommand + flags := infoCommand.Flags() + + flags.BoolVarP(&infoCommand.Debug, "debug", "D", false, "Display additional debug information") + flags.StringVarP(&infoCommand.Format, "format", "f", "", "Change the output format to JSON or a Go template") + + rootCmd.AddCommand(infoCommand.Command) +} + +func infoCmd(c *cliconfig.InfoValues) error { info := map[string]interface{}{} remoteClientInfo := map[string]interface{}{} - runtime, err := adapter.GetRuntime(c) + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } @@ -59,7 +61,7 @@ func infoCmd(c *cli.Context) error { infoArr = append(infoArr, libpod.InfoData{Type: "client", Data: remoteClientInfo}) } - if !runtime.Remote && c.Bool("debug") { + if !runtime.Remote && c.Debug { debugInfo := debugInfo(c) infoArr = append(infoArr, libpod.InfoData{Type: "debug", Data: debugInfo}) } @@ -69,7 +71,7 @@ func infoCmd(c *cli.Context) error { } var out formats.Writer - infoOutputFormat := c.String("format") + infoOutputFormat := c.Format switch infoOutputFormat { case formats.JSONString: out = formats.JSONStruct{Output: info} @@ -85,11 +87,11 @@ func infoCmd(c *cli.Context) error { } // top-level "debug" info -func debugInfo(c *cli.Context) map[string]interface{} { +func debugInfo(c *cliconfig.InfoValues) map[string]interface{} { info := map[string]interface{}{} info["compiler"] = rt.Compiler info["go version"] = rt.Version() - info["podman version"] = c.App.Version + info["podman version"] = version.Version version, _ := libpod.GetVersion() info["git commit"] = version.GitCommit return info |