diff --git a/modules/mesh-cli/cmd/mesh-cli/commands.go b/modules/mesh-cli/cmd/mesh-cli/commands.go index 98a30c23..311bfa74 100644 --- a/modules/mesh-cli/cmd/mesh-cli/commands.go +++ b/modules/mesh-cli/cmd/mesh-cli/commands.go @@ -7,6 +7,7 @@ package main import ( "encoding/json" "fmt" + "io" "sort" "strconv" "strings" @@ -689,9 +690,15 @@ func renderNodes(text string) string { } `json:"placement"` } `json:"keys"` } - if err := json.Unmarshal([]byte(text), &p); err != nil || len(p.Keys) == 0 { + // The console says after the answer which machine answered it ("answered by ace"): kept, below the lines. + dec := json.NewDecoder(strings.NewReader(text)) + if err := dec.Decode(&p); err != nil || len(p.Keys) == 0 { return text } + after := "" + if rest, err := io.ReadAll(dec.Buffered()); err == nil { + after = strings.TrimSpace(string(rest)) + } names := make([]string, 0, len(p.Keys)) for n := range p.Keys { names = append(names, n) @@ -703,6 +710,9 @@ func renderNodes(text string) string { fmt.Fprintf(&b, "%-10s %-15v %-8v %d modules\n", n, orDash(k.Placement.Decided["address"]), orDash(k.Placement.Decided["site"]), len(k.Placement.Modules)) } + if after != "" { + b.WriteString(after + "\n") + } return b.String() } diff --git a/modules/mesh-cli/cmd/mesh-cli/main_test.go b/modules/mesh-cli/cmd/mesh-cli/main_test.go index 50d4dd82..5839cec3 100644 --- a/modules/mesh-cli/cmd/mesh-cli/main_test.go +++ b/modules/mesh-cli/cmd/mesh-cli/main_test.go @@ -195,10 +195,10 @@ func TestAnswersRefusalsAndSilenceAreSaid(t *testing.T) { t.Errorf("an error answer: exit %d, stdout %q, stderr %q", code, out, errOut) } placement := `{"keys":{"novox":{"placement":{"decided":{"address":"10.10.0.1","site":"hub"},"modules":[{},{}]}},` + - `"ace":{"placement":{"decided":{"address":"10.10.0.2"},"modules":[{}]}}}}` + `"ace":{"placement":{"decided":{"address":"10.10.0.2"},"modules":[{}]}}}}` + "\nanswered by ace" console(t, map[string]string{"mesh-placement.placement": placement}) if code, out, _ := runLine("nodes"); code != 0 || !strings.HasPrefix(out, "ace ") || - !strings.Contains(out, "10.10.0.1") || !strings.Contains(out, "2 modules") { + !strings.Contains(out, "10.10.0.1") || !strings.Contains(out, "2 modules") || !strings.HasSuffix(out, "answered by ace\n") { t.Errorf("nodes: exit %d, %q", code, out) } got = console(t, map[string]string{"mesh_search": `{"matches":[]}`})