Skip to content

Commit

Permalink
Add capability to read tags from CLI
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Chloe Hutchinson committed Mar 1, 2019
1 parent 0250580 commit 69abe55
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"encoding/json"
"fmt"
"strings"

yaml "github.com/sanathkr/go-yaml"
)
Expand All @@ -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})
Expand Down

0 comments on commit 69abe55

Please sign in to comment.