Skip to content

Commit

Permalink
🐛 Fix strip flag
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 22, 2022
1 parent 5329569 commit 0000bdb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cmd/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions internal/visitor/template_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 0000bdb

Please sign in to comment.