2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-03-16 15:19:22 -04:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
|
2015-05-05 00:18:28 -04:00
|
|
|
Cli "github.com/docker/docker/cli"
|
2015-03-24 23:57:23 -04:00
|
|
|
"github.com/docker/docker/pkg/archive"
|
|
|
|
flag "github.com/docker/docker/pkg/mflag"
|
|
|
|
)
|
|
|
|
|
2015-03-25 13:34:41 -04:00
|
|
|
// CmdDiff shows changes on a container's filesystem.
|
|
|
|
//
|
2015-04-02 18:52:34 -04:00
|
|
|
// 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).
|
2015-03-25 13:34:41 -04:00
|
|
|
//
|
|
|
|
// Usage: docker diff CONTAINER
|
2015-03-24 23:57:23 -04:00
|
|
|
func (cli *DockerCli) CmdDiff(args ...string) error {
|
2015-10-08 08:46:21 -04:00
|
|
|
cmd := Cli.Subcmd("diff", []string{"CONTAINER"}, Cli.DockerCommands["diff"].Description, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
cmd.Require(flag.Exact, 1)
|
2015-07-03 05:26:09 -04:00
|
|
|
|
2015-03-28 21:22:46 -04:00
|
|
|
cmd.ParseFlags(args, true)
|
2015-03-24 23:57:23 -04:00
|
|
|
|
2015-04-10 12:53:40 -04:00
|
|
|
if cmd.Arg(0) == "" {
|
|
|
|
return fmt.Errorf("Container name cannot be empty")
|
|
|
|
}
|
|
|
|
|
2016-03-16 15:19:22 -04:00
|
|
|
changes, err := cli.client.ContainerDiff(context.Background(), cmd.Arg(0))
|
2015-03-24 23:57:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-04-02 18:52:34 -04:00
|
|
|
for _, change := range changes {
|
2015-03-24 23:57:23 -04:00
|
|
|
var kind string
|
2015-04-02 18:52:34 -04:00
|
|
|
switch change.Kind {
|
2015-03-24 23:57:23 -04:00
|
|
|
case archive.ChangeModify:
|
|
|
|
kind = "C"
|
|
|
|
case archive.ChangeAdd:
|
|
|
|
kind = "A"
|
|
|
|
case archive.ChangeDelete:
|
|
|
|
kind = "D"
|
|
|
|
}
|
2015-04-02 18:52:34 -04:00
|
|
|
fmt.Fprintf(cli.out, "%s %s\n", kind, change.Path)
|
2015-03-24 23:57:23 -04:00
|
|
|
}
|
2015-04-02 18:52:34 -04:00
|
|
|
|
2015-03-24 23:57:23 -04:00
|
|
|
return nil
|
|
|
|
}
|