diff --git a/api/client/history.go b/api/client/history.go index f8a71c870d..fe092df08a 100644 --- a/api/client/history.go +++ b/api/client/history.go @@ -1,14 +1,12 @@ package client import ( - "encoding/json" "fmt" "strconv" "strings" "text/tabwriter" "time" - "github.com/docker/docker/api/types" Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/pkg/stringid" @@ -28,18 +26,11 @@ func (cli *DockerCli) CmdHistory(args ...string) error { cmd.ParseFlags(args, true) - serverResp, err := cli.call("GET", "/images/"+cmd.Arg(0)+"/history", nil, nil) + history, err := cli.client.ImageHistory(cmd.Arg(0)) if err != nil { return err } - defer serverResp.body.Close() - - history := []types.ImageHistory{} - if err := json.NewDecoder(serverResp.body).Decode(&history); err != nil { - return err - } - w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0) if *quiet { diff --git a/api/client/lib/history.go b/api/client/lib/history.go new file mode 100644 index 0000000000..29064c65fb --- /dev/null +++ b/api/client/lib/history.go @@ -0,0 +1,23 @@ +package lib + +import ( + "encoding/json" + "net/url" + + "github.com/docker/docker/api/types" +) + +// ImageHistory returns the changes in an image in history format. +func (cli *Client) ImageHistory(imageID string) ([]types.ImageHistory, error) { + var history []types.ImageHistory + serverResp, err := cli.GET("/images/"+imageID+"/history", url.Values{}, nil) + if err != nil { + return history, err + } + defer serverResp.body.Close() + + if err := json.NewDecoder(serverResp.body).Decode(&history); err != nil { + return history, err + } + return history, nil +}