2015-03-24 23:57:23 -04:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2015-04-02 18:52:34 -04:00
|
|
|
"encoding/json"
|
2015-03-24 23:57:23 -04:00
|
|
|
"fmt"
|
|
|
|
|
2015-04-02 18:52:34 -04:00
|
|
|
"github.com/docker/docker/api/types"
|
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 {
|
|
|
|
cmd := cli.Subcmd("diff", "CONTAINER", "Inspect changes on a container's filesystem", true)
|
|
|
|
cmd.Require(flag.Exact, 1)
|
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")
|
|
|
|
}
|
|
|
|
|
2015-04-02 18:52:34 -04:00
|
|
|
rdr, _, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil)
|
2015-03-24 23:57:23 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2015-04-02 18:52:34 -04:00
|
|
|
changes := []types.ContainerChange{}
|
2015-04-26 12:50:25 -04:00
|
|
|
if err := json.NewDecoder(rdr).Decode(&changes); err != nil {
|
2015-03-24 23:57:23 -04:00
|
|
|
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
|
|
|
|
}
|