mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
filters: use json marshal, instead of beam/data
Docker-DCO-1.1-Signed-off-by: Vincent Batts <vbatts@redhat.com> (github: vbatts)
This commit is contained in:
parent
3ecfaa8f2d
commit
89a15fa235
3 changed files with 30 additions and 8 deletions
|
@ -1172,10 +1172,15 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
matchName := cmd.Arg(0)
|
matchName := cmd.Arg(0)
|
||||||
// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
// FIXME: --viz and --tree are deprecated. Remove them in a future version.
|
||||||
if *flViz || *flTree {
|
if *flViz || *flTree {
|
||||||
|
filterJson, err := filters.ToParam(imageFilterArgs)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
v := url.Values{
|
v := url.Values{
|
||||||
"all": []string{"1"},
|
"all": []string{"1"},
|
||||||
"filters": []string{filters.ToParam(imageFilterArgs)},
|
"filters": []string{filterJson},
|
||||||
}
|
}
|
||||||
|
|
||||||
body, _, err := readBody(cli.call("GET", "/images/json?"+v.Encode(), nil, false))
|
body, _, err := readBody(cli.call("GET", "/images/json?"+v.Encode(), nil, false))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -1237,9 +1242,14 @@ func (cli *DockerCli) CmdImages(args ...string) error {
|
||||||
fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
|
fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
v := url.Values{
|
filterJson, err := filters.ToParam(imageFilterArgs)
|
||||||
"filters": []string{filters.ToParam(imageFilterArgs)},
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
v := url.Values{
|
||||||
|
"filters": []string{filterJson},
|
||||||
|
}
|
||||||
|
|
||||||
if cmd.NArg() == 1 {
|
if cmd.NArg() == 1 {
|
||||||
// FIXME rename this parameter, to not be confused with the filters flag
|
// FIXME rename this parameter, to not be confused with the filters flag
|
||||||
v.Set("filter", matchName)
|
v.Set("filter", matchName)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package filters
|
package filters
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/dotcloud/docker/pkg/beam/data"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,13 +40,22 @@ var ErrorBadFormat = errors.New("bad format of filter (expected name=value)")
|
||||||
/*
|
/*
|
||||||
packs the Args into an string for easy transport from client to server
|
packs the Args into an string for easy transport from client to server
|
||||||
*/
|
*/
|
||||||
func ToParam(a Args) string {
|
func ToParam(a Args) (string, error) {
|
||||||
return data.Encode(a)
|
buf, err := json.Marshal(a)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(buf), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
unpacks the filter Args
|
unpacks the filter Args
|
||||||
*/
|
*/
|
||||||
func FromParam(p string) (Args, error) {
|
func FromParam(p string) (Args, error) {
|
||||||
return data.Decode(p)
|
args := Args{}
|
||||||
|
err := json.Unmarshal([]byte(p), &args)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return args, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,10 @@ func TestParam(t *testing.T) {
|
||||||
"image.name": []string{"ubuntu*", "*untu"},
|
"image.name": []string{"ubuntu*", "*untu"},
|
||||||
}
|
}
|
||||||
|
|
||||||
v := ToParam(a)
|
v, err := ToParam(a)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("failed to marshal the filters: %s", err)
|
||||||
|
}
|
||||||
v1, err := FromParam(v)
|
v1, err := FromParam(v)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("%s", err)
|
t.Errorf("%s", err)
|
||||||
|
|
Loading…
Add table
Reference in a new issue