Make `docker load` to output json when the response content type is json.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
eacedcbe21
commit
9fd2c0feb0
|
|
@ -53,7 +53,7 @@ type apiClient interface {
|
||||||
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error)
|
ImageImport(options types.ImageImportOptions) (io.ReadCloser, error)
|
||||||
ImageInspectWithRaw(imageID string, getSize bool) (types.ImageInspect, []byte, error)
|
ImageInspectWithRaw(imageID string, getSize bool) (types.ImageInspect, []byte, error)
|
||||||
ImageList(options types.ImageListOptions) ([]types.Image, error)
|
ImageList(options types.ImageListOptions) ([]types.Image, error)
|
||||||
ImageLoad(input io.Reader) (io.ReadCloser, error)
|
ImageLoad(input io.Reader) (types.ImageLoadResponse, error)
|
||||||
ImagePull(options types.ImagePullOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error)
|
ImagePull(options types.ImagePullOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error)
|
||||||
ImagePush(options types.ImagePushOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error)
|
ImagePush(options types.ImagePushOptions, privilegeFunc lib.RequestPrivilegeFunc) (io.ReadCloser, error)
|
||||||
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error)
|
ImageRemove(options types.ImageRemoveOptions) ([]types.ImageDelete, error)
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,20 @@ package lib
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/docker/docker/api/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ImageLoad loads an image in the docker host from the client host.
|
// ImageLoad loads an image in the docker host from the client host.
|
||||||
// It's up to the caller to close the io.ReadCloser returned by
|
// It's up to the caller to close the io.ReadCloser returned by
|
||||||
// this function.
|
// this function.
|
||||||
func (cli *Client) ImageLoad(input io.Reader) (io.ReadCloser, error) {
|
func (cli *Client) ImageLoad(input io.Reader) (types.ImageLoadResponse, error) {
|
||||||
resp, err := cli.postRaw("/images/load", url.Values{}, input, nil)
|
resp, err := cli.postRaw("/images/load", url.Values{}, input, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return types.ImageLoadResponse{}, err
|
||||||
}
|
}
|
||||||
return resp.body, nil
|
return types.ImageLoadResponse{
|
||||||
|
Body: resp.body,
|
||||||
|
JSON: resp.header.Get("Content-Type") == "application/json",
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
Cli "github.com/docker/docker/cli"
|
Cli "github.com/docker/docker/cli"
|
||||||
|
"github.com/docker/docker/pkg/jsonmessage"
|
||||||
flag "github.com/docker/docker/pkg/mflag"
|
flag "github.com/docker/docker/pkg/mflag"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -29,12 +30,16 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
|
||||||
input = file
|
input = file
|
||||||
}
|
}
|
||||||
|
|
||||||
responseBody, err := cli.client.ImageLoad(input)
|
response, err := cli.client.ImageLoad(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer responseBody.Close()
|
defer response.Body.Close()
|
||||||
|
|
||||||
_, err = io.Copy(cli.out, responseBody)
|
if response.JSON {
|
||||||
|
return jsonmessage.DisplayJSONMessagesStream(response.Body, cli.out, cli.outFd, cli.isTerminalOut)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = io.Copy(cli.out, response.Body)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -179,6 +179,12 @@ type ImageListOptions struct {
|
||||||
Filters filters.Args
|
Filters filters.Args
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ImageLoadResponse returns information to the client about a load process.
|
||||||
|
type ImageLoadResponse struct {
|
||||||
|
Body io.ReadCloser
|
||||||
|
JSON bool
|
||||||
|
}
|
||||||
|
|
||||||
// ImagePullOptions holds information to pull images.
|
// ImagePullOptions holds information to pull images.
|
||||||
type ImagePullOptions struct {
|
type ImagePullOptions struct {
|
||||||
ImageID string
|
ImageID string
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue