[#139] add shellquote and toMinJson template functions

This commit is contained in:
Cory Bennett
2018-01-07 10:49:00 -08:00
parent 425fa63d33
commit 8c7ca383f6
+12 -1
View File
@@ -8,8 +8,8 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"reflect"
"regexp"
"strconv"
"strings"
"text/template"
@@ -17,6 +17,7 @@ import (
yaml "gopkg.in/coryb/yaml.v2"
"github.com/coryb/figtree"
shellquote "github.com/kballard/go-shellquote"
"github.com/mgutz/ansi"
"golang.org/x/crypto/ssh/terminal"
)
@@ -74,6 +75,16 @@ func TemplateProcessor() *template.Template {
}
return out
},
"shellquote": func(content string) string {
return shellquote.Join(content)
},
"toMinJson": func(content interface{}) (string, error) {
bytes, err := json.Marshal(content)
if err != nil {
return "", err
}
return string(bytes), nil
},
"toJson": func(content interface{}) (string, error) {
bytes, err := json.MarshalIndent(content, "", " ")
if err != nil {