Implement docker history with the standalone client lib.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2015-12-03 14:54:31 -05:00
parent e0549b8ceb
commit 45eca43f5b
2 changed files with 24 additions and 10 deletions

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 {

23
api/client/lib/history.go Normal file
View file

@ -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
}