Implement docker history with the standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
Upstream-commit: 45eca43f5bead5d9d22e65e0609410b266c32e18
Component: engine
This commit is contained in:
David Calavera
2015-12-09 12:04:54 -05:00
parent f30cba0e0e
commit b2a93e0881
2 changed files with 24 additions and 10 deletions
+1 -10
View File
@@ -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 {
@@ -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
}