From 45eca43f5bead5d9d22e65e0609410b266c32e18 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Thu, 3 Dec 2015 14:54:31 -0500 Subject: [PATCH] Implement docker history with the standalone client lib. Signed-off-by: David Calavera --- api/client/history.go | 11 +---------- api/client/lib/history.go | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 api/client/lib/history.go 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 +}