diff --git a/content/content.go b/content/content.go index 15914d5..2ca0dc2 100644 --- a/content/content.go +++ b/content/content.go @@ -68,6 +68,15 @@ func (obj Object) CheckFileType(log *logrus.Logger) string { return FileTypeUnknown } +func Marshal(data interface{}) (Object, error) { + out, err := json.Marshal(data) + if err != nil { + return "", err + } + + return Object(out), nil +} + // String should return the string equivalent of Object. func (obj Object) String() string { return string(obj) diff --git a/content/content_test.go b/content/content_test.go index 0938a33..ddcdf00 100644 --- a/content/content_test.go +++ b/content/content_test.go @@ -82,7 +82,7 @@ name: "testing"`) strReader := new(bytes.Buffer) - render := renderer.GetRenderer(strReader, log, false, false, false, true) + render := renderer.GetRenderer(strReader, log, false, false, false, false, true) err := render.Render(data) assert.NoError(t, err) diff --git a/renderer/color_test.go b/renderer/color_test.go index c0669a6..ce58ede 100644 --- a/renderer/color_test.go +++ b/renderer/color_test.go @@ -18,7 +18,7 @@ func Test_colorJSON(t *testing.T) { cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logrus.New()) strReader := new(bytes.Buffer) - config := renderer.GetRenderer(strReader, logrus.New(), false, true, false, false) + config := renderer.GetRenderer(strReader, logrus.New(), false, false, true, false, false) colorString, err := config.ColorJSON(cliShellReadConfig) assert.NoError(t, err) @@ -33,7 +33,7 @@ func Test_colorJSON(t *testing.T) { assert.NoError(t, err) strReader := new(bytes.Buffer) - config := renderer.GetRenderer(strReader, logrus.New(), true, false, false, false) + config := renderer.GetRenderer(strReader, logrus.New(), false, true, false, false, false) colorString, err := config.ColorYAML(string(valueYAML)) assert.NoError(t, err) diff --git a/renderer/render_test.go b/renderer/render_test.go index 7cb9e8a..b97047e 100644 --- a/renderer/render_test.go +++ b/renderer/render_test.go @@ -18,7 +18,7 @@ func TestGetRenderer(t *testing.T) { strReader := new(bytes.Buffer) logger := logrus.New() - render := renderer.GetRenderer(strReader, logger, false, false, true, false) + render := renderer.GetRenderer(strReader, logger, false, false, false, true, false) inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}} cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger) @@ -35,7 +35,7 @@ func TestGetRenderer(t *testing.T) { strReader := new(bytes.Buffer) logger := logrus.New() - render := renderer.GetRenderer(strReader, logger, false, true, false, false) + render := renderer.GetRenderer(strReader, logger, false, false, true, false, false) inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}} cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger) @@ -52,7 +52,7 @@ func TestGetRenderer(t *testing.T) { strReader := new(bytes.Buffer) logger := logrus.New() - render := renderer.GetRenderer(strReader, logger, true, false, false, false) + render := renderer.GetRenderer(strReader, logger, false, true, false, false, false) inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}} cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger) @@ -70,7 +70,7 @@ func TestGetRenderer(t *testing.T) { logger := logrus.New() logger.SetLevel(logrus.DebugLevel) - render := renderer.GetRenderer(strReader, logger, false, false, false, true) + render := renderer.GetRenderer(strReader, logger, false, false, false, false, true) data := [][]string{ {"sn", "cat", "value"}, @@ -92,7 +92,7 @@ func TestGetRenderer(t *testing.T) { strReader := new(bytes.Buffer) logger := logrus.New() - render := renderer.GetRenderer(strReader, logger, false, false, false, false) + render := renderer.GetRenderer(strReader, logger, false, false, false, false, false) inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}} cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger) @@ -103,7 +103,7 @@ func TestGetRenderer(t *testing.T) { t.Run("should render in defaults to stdout since no writer or render type specified", func(t *testing.T) { logger := logrus.New() - render := renderer.GetRenderer(nil, logger, false, false, false, false) + render := renderer.GetRenderer(nil, logger, false, false, false, false, false) inputOptions := []prompt.Options{{Name: "yes", Short: "y"}, {Name: "no", Short: "n"}} cliShellReadConfig := prompt.NewReadConfig("gocd-cli", "this is test message", inputOptions, logger) @@ -124,7 +124,7 @@ func TestGetRenderer(t *testing.T) { } logger := logrus.New() - render := renderer.GetRenderer(os.Stdout, logger, true, false, false, false) + render := renderer.GetRenderer(os.Stdout, logger, false, true, false, false, false) if err := render.Render(newObject); err != nil { log.Fatal(err)