-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP -- a sketch of something working; some tests are broken
- Loading branch information
Showing
7 changed files
with
102 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright 2020 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package workspace | ||
|
||
import ( | ||
"github.com/vmware-tanzu/carvel-ytt/pkg/filepos" | ||
"github.com/vmware-tanzu/carvel-ytt/pkg/template" | ||
"github.com/vmware-tanzu/carvel-ytt/pkg/yamlmeta" | ||
"github.com/vmware-tanzu/carvel-ytt/pkg/yamltemplate" | ||
) | ||
|
||
// CommentPostProcessing is an instance of the process of filling in templated comments into the configured document | ||
// set. | ||
type CommentPostProcessing struct { | ||
docSets map[*FileInLibrary]*yamlmeta.DocumentSet | ||
} | ||
|
||
// Visit converts annotated comments into YAML comments | ||
func (o CommentPostProcessing) Visit(node yamlmeta.Node) error { | ||
comments := []*yamlmeta.Comment{} | ||
anns := template.NewAnnotations(node) | ||
if anns.Has(yamltemplate.AnnotationHeadComment) { | ||
comments = append(comments, &yamlmeta.Comment{ | ||
Data: anns.Args(yamltemplate.AnnotationHeadComment)[0].String(), | ||
Position: filepos.NewUnknownPosition(), | ||
}) | ||
} | ||
if anns.Has(yamltemplate.AnnotationLineComment) { | ||
comments = append(comments, &yamlmeta.Comment{ | ||
Data: anns.Args(yamltemplate.AnnotationLineComment)[0].String(), | ||
Position: node.GetPosition(), | ||
}) | ||
} | ||
node.SetComments(comments) | ||
return nil | ||
} | ||
|
||
// Apply performs comment post-processing on the configured document set. | ||
func (o CommentPostProcessing) Apply() (map[*FileInLibrary]*yamlmeta.DocumentSet, error) { | ||
for _, docSet := range o.docSets { | ||
err := yamlmeta.Walk(docSet, o) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return o.docSets, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Copyright 2020 VMware, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package yamltemplate | ||
|
||
import "github.com/vmware-tanzu/carvel-ytt/pkg/template" | ||
|
||
// Comment annotation names | ||
const ( | ||
AnnotationYAMLComment template.AnnotationName = "yaml/comment" | ||
AnnotationHeadComment template.AnnotationName = "yaml/head-comment" | ||
AnnotationLineComment template.AnnotationName = "yaml/line-comment" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters