Skip to content

Commit

Permalink
feat: add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasjarosch committed Jun 13, 2023
1 parent eb29726 commit cf36353
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func CopyFile(fs afero.Fs, sourcePath, targetPath string) error {
return nil
}

// CopyFileFsToFs will copy the given sourcePath to the targetPath inside the passed afero.Fs.
// CopyFileFsToFs will a file from the given sourceFs and sourcePath to the targetFs and targetPath
func CopyFileFsToFs(sourceFs afero.Fs, targetFs afero.Fs, sourcePath, targetPath string) error {
sourceExists, err := afero.Exists(sourceFs, sourcePath)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ func LoadSkipperConfig(file *YamlFile, rootKey string) (*SkipperConfig, error) {
return nil, fmt.Errorf("failed to unmarshal SkipperConfig: %w", err)
}

// ensure ignore regex can be compiled
for _, regex := range config.IgnoreRegex {
_, err := regexp.Compile(regex)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ func (t *Templater) Execute(template *File, data any, allowNoValue bool, renameC
return t.execute(template, data, template.Path, allowNoValue)
}

// execute is the main rendering function for templates
func (t *Templater) execute(tplFile *File, data any, targetPath string, allowNoValue bool) error {

// if the template matches any IgnoreRegex, just copy the file to the targetPath
// without rendering it as template
for _, v := range t.IgnoreRegex {
if v.MatchString(tplFile.Path) {
err := CopyFileFsToFs(t.templateFs, t.outputFs, tplFile.Path, targetPath)
Expand All @@ -142,6 +146,7 @@ func (t *Templater) execute(tplFile *File, data any, targetPath string, allowNoV
return nil
}
}

err := tplFile.Load(t.templateFs)
if err != nil {
return err
Expand Down

0 comments on commit cf36353

Please sign in to comment.