Skip to content

Commit

Permalink
Merge pull request #11 from cultureamp/crh/extend-tag-handling
Browse files Browse the repository at this point in the history
Add capability to read additional tags from CLI
  • Loading branch information
pda authored Mar 1, 2019
2 parents 0250580 + 69abe55 commit 45e7f4c
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 45e7f4c

Please sign in to comment.