mirror of
https://github.com/containers/podman.git
synced 2025-12-03 11:49:18 +08:00
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>
This commit is contained in:
@@ -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 {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user