From 0000bdb3cce418db69df95f914e8652032fc4359 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Thu, 22 Sep 2022 17:41:35 -0500 Subject: [PATCH] :bug: Fix strip flag --- cmd/cmd_test.go | 4 ++++ internal/visitor/template_comments.go | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/cmd/cmd_test.go b/cmd/cmd_test.go index 2e75764..5ede5a6 100644 --- a/cmd/cmd_test.go +++ b/cmd/cmd_test.go @@ -94,6 +94,9 @@ func Test_templateReader(t *testing.T) { failConf := config.New() failConf.Fail = true + stripConf := config.New() + stripConf.Strip = true + type args struct { conf config.Config r io.Reader @@ -116,6 +119,7 @@ func Test_templateReader(t *testing.T) { {"invalid yaml", args{conf, strings.NewReader("a:\n- b\n c: c")}, "", true}, {"unset value allowed", args{conf, strings.NewReader("a: a #yampl {{ .b }}")}, "a: a #yampl {{ .b }}\n", false}, {"unset value error", args{failConf, strings.NewReader("a: a #yampl {{ .z }}")}, "", true}, + {"strip", args{stripConf, strings.NewReader("a: a #yampl b")}, "a: b\n", false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { diff --git a/internal/visitor/template_comments.go b/internal/visitor/template_comments.go index b277050..4dc2051 100644 --- a/internal/visitor/template_comments.go +++ b/internal/visitor/template_comments.go @@ -95,6 +95,10 @@ func (t TemplateComments) Template(n *yaml.Node, tmplSrc string, tmplTag comment t.conf.Values["Value"] = n.Value } + if t.conf.Strip { + n.LineComment = "" + } + var buf bytes.Buffer if err = tmpl.Execute(&buf, t.conf.Values); err != nil { return NodeErr{Err: err, Node: n}