github.com/ncdc/docker@v0.10.1-0.20160129113957-6c6729ef5b74/api/client/diff.go (about)

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