github.com/gunjan5/docker@v1.8.2/api/client/diff.go (about) 1 package client 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/docker/docker/api/types" 8 Cli "github.com/docker/docker/cli" 9 "github.com/docker/docker/pkg/archive" 10 flag "github.com/docker/docker/pkg/mflag" 11 ) 12 13 // CmdDiff shows changes on a container's filesystem. 14 // 15 // Each changed file is printed on a separate line, prefixed with a single 16 // character that indicates the status of the file: C (modified), A (added), 17 // or D (deleted). 18 // 19 // Usage: docker diff CONTAINER 20 func (cli *DockerCli) CmdDiff(args ...string) error { 21 cmd := Cli.Subcmd("diff", []string{"CONTAINER"}, "Inspect changes on a container's filesystem", true) 22 cmd.Require(flag.Exact, 1) 23 24 cmd.ParseFlags(args, true) 25 26 if cmd.Arg(0) == "" { 27 return fmt.Errorf("Container name cannot be empty") 28 } 29 30 serverResp, err := cli.call("GET", "/containers/"+cmd.Arg(0)+"/changes", nil, nil) 31 if err != nil { 32 return err 33 } 34 35 defer serverResp.body.Close() 36 37 changes := []types.ContainerChange{} 38 if err := json.NewDecoder(serverResp.body).Decode(&changes); err != nil { 39 return err 40 } 41 42 for _, change := range changes { 43 var kind string 44 switch change.Kind { 45 case archive.ChangeModify: 46 kind = "C" 47 case archive.ChangeAdd: 48 kind = "A" 49 case archive.ChangeDelete: 50 kind = "D" 51 } 52 fmt.Fprintf(cli.out, "%s %s\n", kind, change.Path) 53 } 54 55 return nil 56 }