mirror of https://github.com/docker/compose.git
Return json array for `ps/ls --format json` commands
Signed-off-by: aiordache <anca.iordache@docker.com>
This commit is contained in:
parent
b95c9a987e
commit
83716a5eb2
|
@ -35,15 +35,11 @@ func Print(toJSON interface{}, format string, outWriter io.Writer, writerFn func
|
||||||
case JSON:
|
case JSON:
|
||||||
switch reflect.TypeOf(toJSON).Kind() {
|
switch reflect.TypeOf(toJSON).Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
s := reflect.ValueOf(toJSON)
|
outJSON, err := ToJSON(toJSON, "", "")
|
||||||
for i := 0; i < s.Len(); i++ {
|
|
||||||
obj := s.Index(i).Interface()
|
|
||||||
jsonLine, err := ToJSON(obj, "", "")
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, _ = fmt.Fprint(outWriter, jsonLine)
|
_, _ = fmt.Fprint(outWriter, outJSON)
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
outJSON, err := ToStandardJSON(toJSON)
|
outJSON, err := ToStandardJSON(toJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -57,7 +57,6 @@ func TestPrint(t *testing.T) {
|
||||||
_, _ = fmt.Fprintf(w, "%s\t%s\n", t.Name, t.Status)
|
_, _ = fmt.Fprintf(w, "%s\t%s\n", t.Name, t.Status)
|
||||||
}
|
}
|
||||||
}, "NAME", "STATUS"))
|
}, "NAME", "STATUS"))
|
||||||
assert.Equal(t, b.String(), `{"Name":"myName1","Status":"myStatus1"}
|
assert.Equal(t, b.String(), `[{"Name":"myName1","Status":"myStatus1"},{"Name":"myName2","Status":"myStatus2"}]
|
||||||
{"Name":"myName2","Status":"myStatus2"}
|
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"Current":true,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"npipe:////./pipe/docker_engine","KubernetesEndpoint":"","Type":"moby","Name":"default","StackOrchestrator":"swarm"}
|
[{"Current":true,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"npipe:////./pipe/docker_engine","KubernetesEndpoint":"","Type":"moby","Name":"default","StackOrchestrator":"swarm"}]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"Current":true,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"unix:///var/run/docker.sock","KubernetesEndpoint":"","Type":"moby","Name":"default","StackOrchestrator":"swarm"}
|
[{"Current":true,"Description":"Current DOCKER_HOST based configuration","DockerEndpoint":"unix:///var/run/docker.sock","KubernetesEndpoint":"","Type":"moby","Name":"default","StackOrchestrator":"swarm"}]
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
{"ID":"id","Image":"nginx","Status":"","Command":"","Ports":[]}
|
[{"ID":"id","Image":"nginx","Status":"","Command":"","Ports":[]},{"ID":"1234","Image":"alpine","Status":"","Command":"","Ports":[]}]
|
||||||
{"ID":"1234","Image":"alpine","Status":"","Command":"","Ports":[]}
|
|
||||||
|
|
Loading…
Reference in New Issue