From 69abe5508c307a7de29456eca12856f4d677f3f9 Mon Sep 17 00:00:00 2001 From: Chloe Hutchinson Date: Fri, 1 Mar 2019 11:40:44 +1100 Subject: [PATCH] Add capability to read tags from CLI Added the capability to read extra tags on the CLI input as positional arguments if you're using the --tags parameter. This will allow simple overriding of tags defined in the tags file just like it does when using this functionality with cfn parameters. --- tags.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/tags.go b/tags.go index 276001c..0f0ceed 100644 --- a/tags.go +++ b/tags.go @@ -2,6 +2,8 @@ package main import ( "encoding/json" + "fmt" + "strings" yaml "github.com/sanathkr/go-yaml" ) @@ -13,7 +15,22 @@ type jsonItem struct { func getJsonForInputTags(input *Input) ([]byte, error) { data := map[string]string{} - yaml.Unmarshal(input.TagsBody, &data) + + // Tags from YAML file + err := yaml.Unmarshal(input.TagsBody, &data) + if err != nil { + return nil, err + } + + // Tags from CLI + for _, kv := range input.ParametersCLI { + pair := strings.SplitN(kv, "=", 2) + if len(pair) != 2 { + return nil, fmt.Errorf("expected key=value, got %s", pair) + } + data[pair[0]] = pair[1] + } + items := []jsonItem{} for key, value := range data { items = append(items, jsonItem{Key: key, Value: value})