Skip to content

Commit

Permalink
🐛 (strip): Make --strip flag more consistent
Browse files Browse the repository at this point in the history
Now, comments will be stripped from output even if a template error occurs
  • Loading branch information
gabe565 committed Mar 6, 2023
1 parent 739cb72 commit cc204b6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions internal/visitor/template_comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (t TemplateComments) Run(n *yaml.Node) error {
// Node has no children. Template current node.
tmplSrc, tmplTag := comment.Parse(t.conf.Prefix, n)
if tmplSrc != "" {
if t.conf.Strip {
n.LineComment = ""
}

if err := t.Template(n, tmplSrc, tmplTag); err != nil {
if t.conf.Fail {
return err
Expand All @@ -45,6 +49,10 @@ func (t TemplateComments) Run(n *yaml.Node) error {

tmplSrc, tmplTag := comment.Parse(t.conf.Prefix, key)
if tmplSrc != "" {
if t.conf.Strip {
key.LineComment = ""
}

if err := t.Template(val, tmplSrc, tmplTag); err != nil {
if t.conf.Fail {
return err
Expand All @@ -53,11 +61,7 @@ func (t TemplateComments) Run(n *yaml.Node) error {
}
} else {
// Current node was templated, do not need to traverse children
if t.conf.Strip {
key.LineComment = ""
} else {
comment.Move(key, val)
}
comment.Move(key, val)
continue
}
}
Expand Down Expand Up @@ -99,10 +103,6 @@ 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 cc204b6

Please sign in to comment.