engine

package
v1.223.1-rc.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	Path        string      // Path to the file, may contain template syntax for dynamic naming
	Content     string      // File content, processed as template if IsTemplate is true
	IsTemplate  bool        // Whether to process Content as a Go template
	Permissions os.FileMode // Unix file permissions to apply when creating the file
}

File represents a file to be processed by the templating engine. It contains the file path (which can itself be a template), the content, whether the content should be processed as a template, and the file permissions.

type FileSkippedError

type FileSkippedError struct {
	Path         string // Original file path from the template
	RenderedPath string // Rendered path after template processing
}

FileSkippedError represents when a file is intentionally skipped during processing. Files may be skipped when their rendered path contains empty segments, special values like "false" or "<no value>", or other indicators that the file should not be created.

func (*FileSkippedError) Error

func (e *FileSkippedError) Error() string

Error returns a formatted error message indicating the file was skipped.

type Processor

type Processor struct {
	DryRun bool // When true, compute rendering/merge but skip writing to disk
	// contains filtered or unexported fields
}

Processor handles template processing for scaffold and init commands. It provides template rendering with Gomplate and Sprig functions, file path templating, and intelligent file merging capabilities.

func NewProcessor

func NewProcessor() *Processor

NewProcessor creates a new template processor with default settings. The processor is initialized with a 50% threshold for 3-way merges, meaning merges will be rejected if more than 50% of lines would change.

func (*Processor) ContainsUnprocessedTemplates

func (p *Processor) ContainsUnprocessedTemplates(content string) bool

ContainsUnprocessedTemplates checks if the given content contains unprocessed template syntax.

func (*Processor) ContainsUnprocessedTemplatesWithDelimiters

func (p *Processor) ContainsUnprocessedTemplatesWithDelimiters(content string, delimiters []string) bool

ContainsUnprocessedTemplatesWithDelimiters checks if the given content contains unprocessed template syntax with custom delimiters.

func (*Processor) Merge

func (p *Processor) Merge(base, ours, theirs, fileName string) (*merge.MergeResult, error)

Merge performs a 3-way merge using the internal merger. Parameters:

  • base: The original template content (before any processing)
  • ours: The user's current version (what exists on disk)
  • theirs: The new template content (after processing)
  • fileName: The file name for merge strategy detection

func (*Processor) ProcessFile

func (p *Processor) ProcessFile(file File, targetPath string, force, update bool, scaffoldConfig interface{}, userValues map[string]interface{}) error

ProcessFile processes a file with templating support, handling path rendering, skip logic, and merge/overwrite behavior based on flags.

The method performs the following steps:

  1. Renders the file path as a template (supports dynamic file naming)
  2. Checks if the file should be skipped based on the rendered path
  3. Creates necessary directories
  4. Handles existing files based on force/update flags: - force: overwrites existing files - update: performs a 3-way merge with existing content - neither: returns an error if file exists
  5. Processes file content as a template if IsTemplate is true
  6. Writes the final content to disk with specified permissions

Returns FileSkippedError if the file is intentionally skipped (not considered an error).

func (*Processor) ProcessTemplate

func (p *Processor) ProcessTemplate(content string, targetPath string, scaffoldConfig interface{}, userValues map[string]interface{}) (string, error)

ProcessTemplate processes Go templates in file content.

func (*Processor) ProcessTemplateWithDelimiters

func (p *Processor) ProcessTemplateWithDelimiters(content string, targetPath string, scaffoldConfig interface{}, userValues map[string]interface{}, delimiters []string) (string, error)

ProcessTemplateWithDelimiters processes Go templates in file content with custom delimiters.

func (*Processor) SetConflictStrategy

func (p *Processor) SetConflictStrategy(strategy merge.ConflictStrategy)

SetConflictStrategy sets how a real ours/theirs divergence is resolved during a 3-way merge. Note: SetMaxChanges replaces p.merger wholesale, so call SetConflictStrategy after SetMaxChanges if both are used, or the strategy set here would be discarded.

func (*Processor) SetDryRun

func (p *Processor) SetDryRun(dryRun bool)

SetDryRun toggles dry-run mode. When enabled, ProcessFile still renders templates, loads the git merge base, performs the 3-way merge, and runs conflict/threshold checks — every step that can fail — but skips the final write to disk, so a dry-run preview reports real conflicts instead of only listing file paths.

func (*Processor) SetMaxChanges

func (p *Processor) SetMaxChanges(thresholdPercent int)

SetMaxChanges sets the maximum percentage of changes allowed for 3-way merge operations. The thresholdPercent parameter controls how aggressive the merge behavior is: a lower value (e.g., 30) is more conservative, while a higher value (e.g., 80) allows more extensive changes during merges.

func (*Processor) SetupGitStorage

func (p *Processor) SetupGitStorage(targetPath string, baseRef string) error

SetupGitStorage initializes git-based storage for 3-way merges. The targetPath is used to find the git repository and resolve relative file paths. The baseRef specifies which git reference to use as the base for merges (e.g., "main", "v1.0.0").

Returns an error if:

  • targetPath is not in a git repository
  • baseRef cannot be resolved

func (*Processor) ShouldSkipFile

func (p *Processor) ShouldSkipFile(renderedPath string) bool

ShouldSkipFile determines if a file should be skipped based on its rendered path.

Files are skipped in the following cases:

  • Empty path or special values: "", "false", "null", "<no value>"
  • Paths with empty segments: "foo//bar", "/foo", "foo/"
  • Paths that would create invalid filesystem entries

This is useful for conditional file generation where template variables may evaluate to empty or false values, indicating the file should not be created.

func (*Processor) ValidateNoUnprocessedTemplates

func (p *Processor) ValidateNoUnprocessedTemplates(content string) error

ValidateNoUnprocessedTemplates validates that the processed content doesn't contain unprocessed template syntax.

func (*Processor) ValidateNoUnprocessedTemplatesWithDelimiters

func (p *Processor) ValidateNoUnprocessedTemplatesWithDelimiters(content string, delimiters []string) error

ValidateNoUnprocessedTemplatesWithDelimiters validates that the processed content doesn't contain unprocessed template syntax with custom delimiters.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL