Documentation
¶
Overview ¶
Package version messages - error and log message constants Exported so tests can compare against them
Index ¶
- Constants
- func Decrement(level VersionLevel) error
- func EscapedBranchName(branchName string) string
- func GetCurrentVersion() (string, error)
- func GetPrefix() (string, error)
- func Increment(level VersionLevel) error
- func Save(v *Version) error
- func SetMetadata(metadata string) error
- func SetPreRelease(preRelease string) error
- func SetPrefix(prefix string) error
- func StripPrefix(version string) string
- type Version
- func (v *Version) AssemblyVersion() string
- func (v *Version) BuildMetadataWithPlus() string
- func (v *Version) CoreVersion() string
- func (v *Version) DecrementMajor() error
- func (v *Version) DecrementMinor() error
- func (v *Version) DecrementPatch() error
- func (v *Version) FullSemVer() string
- func (v *Version) FullString() string
- func (v *Version) HasBuildMetadata() bool
- func (v *Version) HasPrefix() bool
- func (v *Version) IncrementMajor()
- func (v *Version) IncrementMinor()
- func (v *Version) IncrementPatch()
- func (v *Version) IsPreRelease() bool
- func (v *Version) MajorMinor() string
- func (v *Version) MajorString() string
- func (v *Version) MinorString() string
- func (v *Version) OriginalFullSemVer() string
- func (v *Version) OriginalSemVerString() string
- func (v *Version) OriginalString() string
- func (v *Version) PatchString() string
- func (v *Version) PreReleaseLabel() string
- func (v *Version) PreReleaseLabelWithDash() string
- func (v *Version) PreReleaseNumber() int
- func (v *Version) PreReleaseWithDash() string
- func (v *Version) PrefixedFullSemVer() string
- func (v *Version) PrefixedSemVerString() string
- func (v *Version) PrefixedString() string
- func (v *Version) SemVer() string
- func (v *Version) SemVerString() string
- func (v *Version) String() string
- func (v *Version) Validate() error
- type VersionLevel
Constants ¶
const ( ErrMajorVersionNegative = "major version cannot be negative" ErrMinorVersionNegative = "minor version cannot be negative" ErrPatchVersionNegative = "patch version cannot be negative" ErrCannotDecrementMajor = "cannot decrement major version below 0" ErrCannotDecrementMinor = "cannot decrement minor version below 0" ErrCannotDecrementPatch = "cannot decrement patch version below 0" ErrInvalidVersionLevel = "invalid version level" ErrInvalidPreRelease = "invalid pre-release identifier" ErrInvalidMetadata = "invalid build metadata" ErrEmptyIdentifierPart = "identifier part cannot be empty" ErrInvalidIdentifierChar = "invalid character in identifier" ErrCustomKeyNotFound = "custom key not found" )
Error messages
const ( LogVersionLoaded = "version_loaded" LogVersionSaved = "version_saved" LogVersionIncremented = "version_incremented" LogVersionDecremented = "version_decremented" LogVersionMigrated = "version_migrated" LogVersionParsed = "version_parsed" LogVersionParseError = "version_parse_error" LogVersionCreated = "version_created" LogCustomVarSet = "custom_var_set" LogCustomVarDeleted = "custom_var_deleted" LogPrefixSet = "prefix_set" LogFileReadError = "file_read_error" LogFileWriteError = "file_write_error" )
Log messages for structured logging
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 Decrement ¶
func Decrement(level VersionLevel) error
Decrement decrements the specified version level
func EscapedBranchName ¶
EscapedBranchName takes a branch name and escapes slashes to dashes
func GetCurrentVersion ¶
GetCurrentVersion reads the current version from VERSION file
func Increment ¶
func Increment(level VersionLevel) error
Increment increments the specified version level
func SetPreRelease ¶
SetPreRelease sets the pre-release tag
func SetPrefix ¶
SetPrefix sets the version prefix in the VERSION file The VERSION file is the source of truth - config.Prefix is only used as default for new projects
func StripPrefix ¶
StripPrefix removes the 'v' or 'V' prefix from a version string if present
Types ¶
type Version ¶
type Version struct {
Prefix string // Optional prefix (e.g., "v", "release-")
Major int // Major version
Minor int // Minor version
Patch int // Patch version
PreRelease string // Pre-release identifier (e.g., "alpha.1")
BuildMetadata string // Build metadata (e.g., "build.123")
Raw string // Original parsed string
}
Version represents a semantic version with all components This is the unified struct replacing both SemVer and VersionData
func Load ¶
Load reads the VERSION file and returns the parsed Version If VERSION doesn't exist, creates a default 0.0.0 (using config prefix if set) VERSION file content is the source of truth - it takes priority over config
func Parse ¶
Parse parses a version string into a Version struct Extracts prefix as all characters (letters, dashes) before the first digit Returns a Version with zero values for unparseable input
func (*Version) AssemblyVersion ¶
AssemblyVersion returns an assembly-compatible version (Major.Minor.Patch.0)
func (*Version) BuildMetadataWithPlus ¶
BuildMetadataWithPlus returns the build metadata with a leading plus, or empty if none
func (*Version) CoreVersion ¶
CoreVersion returns just Major.Minor.Patch
func (*Version) DecrementMajor ¶
DecrementMajor decrements the major version, returns error if already 0
func (*Version) DecrementMinor ¶
DecrementMinor decrements the minor version, returns error if already 0
func (*Version) DecrementPatch ¶
DecrementPatch decrements the patch version, returns error if already 0
func (*Version) FullSemVer ¶
FullSemVer returns Major.Minor.Patch[-PreRelease][+BuildMetadata]
func (*Version) FullString ¶
FullString returns the full version string with prefix Format: [Prefix]Major.Minor.Patch[-PreRelease][+BuildMetadata]
func (*Version) HasBuildMetadata ¶
HasBuildMetadata returns true if this version has build metadata
func (*Version) IncrementMajor ¶
func (v *Version) IncrementMajor()
IncrementMajor increments the major version, resets minor and patch
func (*Version) IncrementMinor ¶
func (v *Version) IncrementMinor()
IncrementMinor increments the minor version, resets patch
func (*Version) IncrementPatch ¶
func (v *Version) IncrementPatch()
IncrementPatch increments the patch version
func (*Version) IsPreRelease ¶
IsPreRelease returns true if this version has a pre-release tag
func (*Version) MajorMinor ¶
MajorMinor returns the Major.Minor string
func (*Version) MajorString ¶
MajorString returns the major version as a string
func (*Version) MinorString ¶
MinorString returns the minor version as a string
func (*Version) OriginalFullSemVer ¶
OriginalFullSemVer returns the full semver string preserving the original prefix style
func (*Version) OriginalSemVerString ¶
OriginalSemVerString returns the semver string preserving the original prefix style
func (*Version) OriginalString ¶
OriginalString returns the version in the same format as the input
func (*Version) PatchString ¶
PatchString returns the patch version as a string
func (*Version) PreReleaseLabel ¶
PreReleaseLabel returns just the label portion of the pre-release (e.g., "alpha" from "alpha.5")
func (*Version) PreReleaseLabelWithDash ¶
PreReleaseLabelWithDash returns the pre-release label with a leading dash, or empty if none
func (*Version) PreReleaseNumber ¶
PreReleaseNumber returns the numeric portion of the pre-release (e.g., 5 from "alpha.5") Returns -1 if no numeric portion exists
func (*Version) PreReleaseWithDash ¶
PreReleaseWithDash returns the pre-release with a leading dash, or empty if none
func (*Version) PrefixedFullSemVer ¶
PrefixedFullSemVer returns Major.Minor.Patch[-PreRelease][+BuildMetadata] with the original prefix
func (*Version) PrefixedSemVerString ¶
PrefixedSemVerString returns Major.Minor.Patch[-PreRelease] format with the original prefix
func (*Version) PrefixedString ¶
PrefixedString returns the version with prefix (Major.Minor.Patch)
func (*Version) SemVerString ¶
SemVerString returns Major.Minor.Patch[-PreRelease] format without prefix
type VersionLevel ¶
type VersionLevel int
VersionLevel represents the semantic version component to modify
const ( MajorLevel VersionLevel = iota MinorLevel PatchLevel )