summaryrefslogtreecommitdiff
path: root/cmd/podman/diff.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/diff.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/diff.go')
-rw-r--r--cmd/podman/diff.go60
1 files changed, 30 insertions, 30 deletions
diff --git a/cmd/podman/diff.go b/cmd/podman/diff.go
index 5f813699f..04a659ab6 100644
--- a/cmd/podman/diff.go
+++ b/cmd/podman/diff.go
@@ -2,12 +2,12 @@ package main
import (
"fmt"
-
+ "github.com/containers/libpod/cmd/podman/cliconfig"
"github.com/containers/libpod/cmd/podman/formats"
"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/storage/pkg/archive"
"github.com/pkg/errors"
- "github.com/urfave/cli"
+ "github.com/spf13/cobra"
)
type diffJSONOutput struct {
@@ -33,31 +33,35 @@ func (so stdoutStruct) Out() error {
}
var (
- diffFlags = []cli.Flag{
- cli.BoolFlag{
- Name: "archive",
- Usage: "Save the diff as a tar archive",
- Hidden: true,
- },
- cli.StringFlag{
- Name: "format",
- Usage: "Change the output format.",
- },
- }
+ diffCommand cliconfig.DiffValues
diffDescription = fmt.Sprint(`Displays changes on a container or image's filesystem. The
container or image will be compared to its parent layer`)
- diffCommand = cli.Command{
- Name: "diff",
- Usage: "Inspect changes on container's file systems",
- Description: diffDescription,
- Flags: sortFlags(diffFlags),
- Action: diffCmd,
- ArgsUsage: "ID-NAME",
- OnUsageError: usageErrorHandler,
+ _diffCommand = &cobra.Command{
+ Use: "diff",
+ Short: "Inspect changes on container's file systems",
+ Long: diffDescription,
+ RunE: func(cmd *cobra.Command, args []string) error {
+ diffCommand.InputArgs = args
+ diffCommand.GlobalFlags = MainGlobalOpts
+ return diffCmd(&diffCommand)
+ },
+ Example: "ID-NAME",
}
)
+func init() {
+ diffCommand.Command = _diffCommand
+ flags := diffCommand.Flags()
+
+ flags.BoolVar(&diffCommand.Archive, "archive", true, "Save the diff as a tar archive")
+ flags.StringVar(&diffCommand.Format, "format", "", "Change the output format")
+
+ flags.MarkHidden("archive")
+
+ rootCmd.AddCommand(diffCommand.Command)
+
+}
func formatJSON(output []diffOutputParams) (diffJSONOutput, error) {
jsonStruct := diffJSONOutput{}
for _, output := range output {
@@ -75,29 +79,25 @@ func formatJSON(output []diffOutputParams) (diffJSONOutput, error) {
return jsonStruct, nil
}
-func diffCmd(c *cli.Context) error {
- if err := validateFlags(c, diffFlags); err != nil {
- return err
- }
-
- if len(c.Args()) != 1 {
+func diffCmd(c *cliconfig.DiffValues) error {
+ if len(c.InputArgs) != 1 {
return errors.Errorf("container, image, or layer name must be specified: podman diff [options [...]] ID-NAME")
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand)
if err != nil {
return errors.Wrapf(err, "could not get runtime")
}
defer runtime.Shutdown(false)
- to := c.Args().Get(0)
+ to := c.InputArgs[0]
changes, err := runtime.GetDiff("", to)
if err != nil {
return errors.Wrapf(err, "could not get changes for %q", to)
}
diffOutput := []diffOutputParams{}
- outputFormat := c.String("format")
+ outputFormat := c.Format
for _, change := range changes {