From 262cbf977cab5cea3c7abc5ff05cfcff47d47b6c Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Wed, 2 Apr 2014 20:03:17 -0700 Subject: [PATCH] beam/examples/beamsh: use beam.Router to simplify 'trace' Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) Upstream-commit: 30424f4e3a40ec21ac25e5c3f9ef45c3109c9f06 Component: engine --- .../pkg/beam/examples/beamsh/builtins.go | 24 ++++++------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/components/engine/pkg/beam/examples/beamsh/builtins.go b/components/engine/pkg/beam/examples/beamsh/builtins.go index d85bafd0fa..2391ab6e00 100644 --- a/components/engine/pkg/beam/examples/beamsh/builtins.go +++ b/components/engine/pkg/beam/examples/beamsh/builtins.go @@ -188,23 +188,13 @@ func CmdExec(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam } func CmdTrace(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam.Sender) { - for { - p, a, err := in.Receive() - if err != nil { - return - } - var msg string - if pretty := data.Message(string(p)).Pretty(); pretty != "" { - msg = pretty - } else { - msg = string(p) - } - if a != nil { - msg = fmt.Sprintf("%s [%d]", msg, a.Fd()) - } - fmt.Printf("===> %s\n", msg) - out.Send(p, a) - } + r := beam.NewRouter(out) + r.NewRoute().All().Handler(func(payload []byte, attachment *os.File) error { + fmt.Printf("===> %s\n", beam.MsgDesc(payload, attachment)) + out.Send(payload, attachment) + return nil + }) + beam.Copy(r, in) } func CmdEmit(args []string, stdout, stderr io.Writer, in beam.Receiver, out beam.Sender) {