emit

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package emit messages - error and log message constants Exported so tests can compare against them

Index

Constants

View Source
const (
	ErrUnsupportedFormat     = "unsupported format"
	ErrTemplateRenderFail    = "failed to render template"
	ErrFileWriteFail         = "failed to write file"
	ErrOutputPathEmpty       = "output path cannot be empty"
	ErrOutputPathIsDirectory = "is a directory, not a file"
	ErrParentDirNotExist     = "does not exist"
	ErrParentNotDirectory    = "is not a directory"
)

Error messages

View Source
const (
	LogTemplateRendered = "template_rendered"
	LogTemplateWritten  = "template_written"
	LogEmitCompleted    = "emit_completed"
)

Log messages for structured logging

View Source
const (
	// FilePermission is the default permission for created files (owner rw, group/other r)
	FilePermission os.FileMode = 0644
)

File permission constants

Variables

This section is empty.

Functions

func EmitTemplateToFile

func EmitTemplateToFile(tmplStr, version, filepath string) error

EmitTemplateToFile renders a custom template and writes to a file

func EmitToFile

func EmitToFile(format Format, version, filepath string) error

EmitToFile renders and writes the version to a file

func GetEmbeddedTemplate

func GetEmbeddedTemplate(format Format) (string, error)

GetEmbeddedTemplate returns the embedded template content for a given format. This is useful for users who want to see the default template for customization.

func IsValidFormat

func IsValidFormat(format string) bool

IsValidFormat checks if the given format is supported

func MergeCustomVars

func MergeCustomVars(data *TemplateData, extraVars map[string]string)

MergeCustomVars merges additional custom variables into TemplateData Command-line values override config values

func Render

func Render(format Format, version string) (string, error)

Render generates the version output for the given format

func RenderTemplate

func RenderTemplate(tmplStr string, versionStr string) (string, error)

RenderTemplate renders a custom Mustache template with the given version

func RenderTemplateList

func RenderTemplateList(templates []string, data TemplateData, sep string) string

RenderTemplateList renders a list of template strings and joins with separator

func RenderTemplateWithData

func RenderTemplateWithData(tmplStr string, data TemplateData) (string, error)

RenderTemplateWithData renders a Mustache template with TemplateData

func SupportedFormats

func SupportedFormats() []string

SupportedFormats returns a list of supported format names

func TemplateDataToStringMap added in v0.1.0

func TemplateDataToStringMap(data TemplateData) map[string]string

TemplateDataToStringMap converts TemplateData to map[string]string for use with mode package

func ValidateOutputPath

func ValidateOutputPath(filepath string) error

ValidateOutputPath checks if an output file path is valid Returns an error if: - The path is empty - The path points to an existing directory - The parent directory doesn't exist and can't be determined

func WriteToFile

func WriteToFile(content, filepath string) error

WriteToFile writes the rendered output to a file Validates the path before writing

Types

type Format

type Format string

Format represents a supported output format

const (
	FormatPython    Format = "python"
	FormatJSON      Format = "json"
	FormatYAML      Format = "yaml"
	FormatGo        Format = "go"
	FormatC         Format = "c"
	FormatCHeader   Format = "c-header"
	FormatCPP       Format = "cpp"
	FormatCPPHeader Format = "cpp-header"
	FormatJS        Format = "js"
	FormatTS        Format = "ts"
	FormatJava      Format = "java"
	FormatKotlin    Format = "kotlin"
	FormatCSharp    Format = "csharp"
	FormatPHP       Format = "php"
	FormatSwift     Format = "swift"
	FormatRuby      Format = "ruby"
	FormatRust      Format = "rust"
)

type TemplateData

type TemplateData struct {
	// Version components
	Major           string // Major version number (e.g., "1")
	Minor           string // Minor version number (e.g., "2")
	Patch           string // Patch version number (e.g., "3")
	Revision        string // Revision number for 4-component versions (e.g., "4"), empty if not set
	MajorMinorPatch string // Core version: Major.Minor.Patch[.Revision] (e.g., "1.2.3" or "1.2.3.4")
	MajorMinor      string // Major.Minor (e.g., "1.2")
	Prefix          string // Version prefix (e.g., "v")

	// Rendered pre-release (from template config, dash-separated items)
	PreRelease         string // Rendered pre-release (e.g., "alpha-5")
	PreReleaseWithDash string // With leading dash (e.g., "-alpha-5")
	PreReleaseLabel    string // Just the label part (e.g., "alpha" from "alpha.5")
	PreReleaseNumber   string // Just the number part (e.g., "5" from "alpha.5")

	// Rendered metadata (from template config, dot-separated items)
	Metadata         string // Rendered metadata (e.g., "20241211103045.4846bcd2e133")
	MetadataWithPlus string // With leading plus (e.g., "+20241211103045.4846bcd2e133")

	// VCS/Git info
	Hash               string // Full commit hash (40 chars for git)
	ShortHash          string // Short commit hash (7 chars)
	MediumHash         string // Medium commit hash (12 chars)
	BranchName         string // Current branch name (e.g., "feature/foo")
	EscapedBranchName  string // Branch name with slashes replaced (e.g., "feature-foo")
	CommitsSinceTag    string // Commits since last tag (e.g., "12")
	BuildNumber        string // Alias for CommitsSinceTag (GitVersion compatibility)
	BuildNumberPadded  string // Padded commits since tag, 4 digits (e.g., "0012")
	UncommittedChanges string // Count of uncommitted changes (e.g., "3")
	Dirty              string // "dirty" if uncommitted changes > 0, empty otherwise
	VersionSourceHash  string // Hash of the commit the last tag points to

	// Commit author info
	CommitAuthor      string // Name of the commit author
	CommitAuthorEmail string // Email of the commit author

	// Commit timestamps (all in UTC)
	CommitDate        string // ISO 8601 format: 2024-01-15T10:30:00Z
	CommitDateCompact string // Compact format: 20240115103045 (YYYYMMDDHHmmss)
	CommitDateShort   string // Date only: 2024-01-15
	CommitYear        string // Year: 2024
	CommitMonth       string // Month: 01 (zero-padded)
	CommitDay         string // Day: 15 (zero-padded)

	// Build timestamps (all in UTC)
	BuildDateTimeUTC     string // ISO 8601 format: 2024-01-15T10:30:00Z
	BuildDateTimeCompact string // Compact format: 20240115103045 (YYYYMMDDHHmmss)
	BuildDateUTC         string // Date only: 2024-01-15
	BuildYear            string // Year: 2024
	BuildMonth           string // Month: 01 (zero-padded)
	BuildDay             string // Day: 15 (zero-padded)

	// Custom holds arbitrary key-value pairs from config and --set flags
	Custom map[string]string

	// PluginVariables holds plugin-specific template variables (e.g., GitShortHash, ShaShortHash from git plugin)
	PluginVariables map[string]string
}

TemplateData holds the data passed to templates

func BuildCompleteTemplateData

func BuildCompleteTemplateData(v *version.Version, prereleaseTemplate, metadataTemplate string) TemplateData

BuildCompleteTemplateData builds TemplateData with PreRelease and Metadata populated prereleaseTemplate: Mustache template for PreRelease (use DASHES as separators) metadataTemplate: Mustache template for Metadata (use DOTS as separators)

func BuildTemplateDataFromVersion

func BuildTemplateDataFromVersion(v *version.Version) TemplateData

BuildTemplateDataFromVersion creates TemplateData from Version This allows rendering templates directly from VERSION data

type VCSInfo

type VCSInfo struct {
	Identifier         string
	IdentifierShort    string // 7 chars
	IdentifierMedium   string // 12 chars
	BranchName         string
	CommitDate         time.Time
	CommitsSinceTag    int
	UncommittedChanges int
	VersionSourceHash  string
	CommitAuthor       string
	CommitAuthorEmail  string
}

VCSInfo holds all VCS-related information

Jump to

Keyboard shortcuts

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