diff --git a/api/client/commands.go b/api/client/commands.go index de787c35ff..5df2ba09cd 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -7,7 +7,6 @@ func (cli *DockerCli) Command(name string) func(...string) error { "build": cli.CmdBuild, "commit": cli.CmdCommit, "cp": cli.CmdCp, - "diff": cli.CmdDiff, "events": cli.CmdEvents, "exec": cli.CmdExec, "history": cli.CmdHistory, diff --git a/api/client/container/diff.go b/api/client/container/diff.go new file mode 100644 index 0000000000..053b9e1647 --- /dev/null +++ b/api/client/container/diff.go @@ -0,0 +1,58 @@ +package container + +import ( + "fmt" + + "golang.org/x/net/context" + + "github.com/docker/docker/api/client" + "github.com/docker/docker/cli" + "github.com/docker/docker/pkg/archive" + "github.com/spf13/cobra" +) + +type diffOptions struct { + container string +} + +// NewDiffCommand creats a new cobra.Command for `docker diff` +func NewDiffCommand(dockerCli *client.DockerCli) *cobra.Command { + var opts diffOptions + + cmd := &cobra.Command{ + Use: "diff CONTAINER", + Short: "Inspect changes on a container's filesystem", + Args: cli.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + opts.container = args[0] + return runDiff(dockerCli, &opts) + }, + } + cmd.SetFlagErrorFunc(flagErrorFunc) + + return cmd +} + +func runDiff(dockerCli *client.DockerCli, opts *diffOptions) error { + ctx := context.Background() + + changes, err := dockerCli.Client().ContainerDiff(ctx, opts.container) + if err != nil { + return err + } + + for _, change := range changes { + var kind string + switch change.Kind { + case archive.ChangeModify: + kind = "C" + case archive.ChangeAdd: + kind = "A" + case archive.ChangeDelete: + kind = "D" + } + fmt.Fprintf(dockerCli.Out(), "%s %s\n", kind, change.Path) + } + + return nil +} diff --git a/api/client/diff.go b/api/client/diff.go deleted file mode 100644 index e17768fd8f..0000000000 --- a/api/client/diff.go +++ /dev/null @@ -1,49 +0,0 @@ -package client - -import ( - "fmt" - - "golang.org/x/net/context" - - Cli "github.com/docker/docker/cli" - "github.com/docker/docker/pkg/archive" - flag "github.com/docker/docker/pkg/mflag" -) - -// CmdDiff shows changes on a container's filesystem. -// -// Each changed file is printed on a separate line, prefixed with a single -// character that indicates the status of the file: C (modified), A (added), -// or D (deleted). -// -// Usage: docker diff CONTAINER -func (cli *DockerCli) CmdDiff(args ...string) error { - cmd := Cli.Subcmd("diff", []string{"CONTAINER"}, Cli.DockerCommands["diff"].Description, true) - cmd.Require(flag.Exact, 1) - - cmd.ParseFlags(args, true) - - if cmd.Arg(0) == "" { - return fmt.Errorf("Container name cannot be empty") - } - - changes, err := cli.client.ContainerDiff(context.Background(), cmd.Arg(0)) - if err != nil { - return err - } - - for _, change := range changes { - var kind string - switch change.Kind { - case archive.ChangeModify: - kind = "C" - case archive.ChangeAdd: - kind = "A" - case archive.ChangeDelete: - kind = "D" - } - fmt.Fprintf(cli.out, "%s %s\n", kind, change.Path) - } - - return nil -} diff --git a/cli/cobraadaptor/adaptor.go b/cli/cobraadaptor/adaptor.go index 4f3558556f..da8fdd194a 100644 --- a/cli/cobraadaptor/adaptor.go +++ b/cli/cobraadaptor/adaptor.go @@ -34,6 +34,7 @@ func NewCobraAdaptor(clientFlags *cliflags.ClientFlags) CobraAdaptor { rootCmd.SetOutput(stdout) rootCmd.AddCommand( container.NewCreateCommand(dockerCli), + container.NewDiffCommand(dockerCli), container.NewExportCommand(dockerCli), container.NewRunCommand(dockerCli), container.NewStartCommand(dockerCli), diff --git a/cli/usage.go b/cli/usage.go index d4cc7ca2dc..846dda8b5e 100644 --- a/cli/usage.go +++ b/cli/usage.go @@ -12,7 +12,6 @@ var DockerCommandUsage = []Command{ {"build", "Build an image from a Dockerfile"}, {"commit", "Create a new image from a container's changes"}, {"cp", "Copy files/folders between a container and the local filesystem"}, - {"diff", "Inspect changes on a container's filesystem"}, {"events", "Get real time events from the server"}, {"exec", "Run a command in a running container"}, {"history", "Show the history of an image"}, diff --git a/integration-cli/docker_cli_diff_test.go b/integration-cli/docker_cli_diff_test.go index 3ec893061e..e046740783 100644 --- a/integration-cli/docker_cli_diff_test.go +++ b/integration-cli/docker_cli_diff_test.go @@ -83,5 +83,5 @@ func (s *DockerSuite) TestDiffEnsureDefaultDevs(c *check.C) { func (s *DockerSuite) TestDiffEmptyArgClientError(c *check.C) { out, _, err := dockerCmdWithError("diff", "") c.Assert(err, checker.NotNil) - c.Assert(strings.TrimSpace(out), checker.Equals, "Container name cannot be empty") + c.Assert(strings.TrimSpace(out), checker.Contains, "\"docker diff\" requires exactly 1 argument(s).") }