mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Implement docker history with the standalone client lib.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
e0549b8ceb
commit
45eca43f5b
2 changed files with 24 additions and 10 deletions
|
@ -1,14 +1,12 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/docker/docker/api/types"
|
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
|
@ -28,18 +26,11 @@ func (cli *DockerCli) CmdHistory(args ...string) error {
|
||||||
|
|
||||||
cmd.ParseFlags(args, true)
|
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 {
|
if err != nil {
|
||||||
return err
|
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)
|
w := tabwriter.NewWriter(cli.out, 20, 1, 3, ' ', 0)
|
||||||
|
|
||||||
if *quiet {
|
if *quiet {
|
||||||
|
|
23
api/client/lib/history.go
Normal file
23
api/client/lib/history.go
Normal 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
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue