From 086724e1a36e29ba86d68cac31507ce539b01e39 Mon Sep 17 00:00:00 2001 From: Solomon Hykes Date: Thu, 27 Mar 2014 18:25:49 -0700 Subject: [PATCH] beam/data: Message.Parse creates a message from shell-style 'key=value' arguments Docker-DCO-1.1-Signed-off-by: Solomon Hykes (github: shykes) --- beam/data/message.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/beam/data/message.go b/beam/data/message.go index e6536f8..193fb7b 100644 --- a/beam/data/message.go +++ b/beam/data/message.go @@ -11,6 +11,22 @@ func Empty() Message { return Message(Encode(nil)) } +func Parse(args []string) Message { + data := make(map[string][]string) + for _, word := range args { + if strings.Contains(word, "=") { + kv := strings.SplitN(word, "=", 2) + key := kv[0] + var val string + if len(kv) == 2 { + val = kv[1] + } + data[key] = []string{val} + } + } + return Message(Encode(data)) +} + func (m Message) Add(k, v string) Message { data, err := Decode(string(m)) if err != nil {