Skip to content

Version Command Customization

HexaGo includes a built-in version command in all generated projects. This page explains how to customize the ASCII art splash that displays when running myapp version.


Default Splash

The default splash displays version information in ASCII art format:

┓┏      ┏┓    Version: 1.0.0
┣┫┏┓┓┏┏┓┃┓┏┓  Build: 2026-04-06T12:00:00Z
┛┗┗ ┛┗┗┻┗┛┗┛  Commit: abc1234

The splash is generated by pkg/version/splash.go using fmt.Fprintf with the version data.


Customizing the ASCII Art

To customize the splash for your project, edit pkg/version/splash.go:

1. Generate Your ASCII Art

Use online tools to create custom ASCII art:

2. Update the Splash Function

Replace the Splash() function in pkg/version/splash.go:

func Splash() {
    v := CurrentVersion()
    extra := ""
    if v.Extra != "" {
        extra = "-" + v.Extra
    }

    fmt.Fprintf(os.Stdout, `
 __  __ 
|  \/  |
| \  / |_   _    __ _ _ __  _ __ 
| |\/| | | | |  / _` | '_ \| '_ \ 
| |  | | |_| | | (_| | |_) | |_) |
|_|  |_|\__, |  \__,_| .__/| .__/   Version: %d.%d.%d%s
         __/ |       | |   | |      Build: %s
        |___/        |_|   |_|      Commit: %s

`, v.Major, v.Minor, v.Patch, extra, v.BuildDate, v.Commit)
}

3. Variables Available

The VersionInfo struct provides these fields:

Field Type Description
Major int Major version number
Minor int Minor version number
Patch int Patch version number
Extra string Extra version suffix (e.g., "rc1", "beta")
Version string Raw version string (e.g., "v1.0.0-rc1")
BuildDate string Build timestamp (RFC3339 format)
Commit string Git commit hash

Using --simple Flag

For scripting or CI pipelines, use the --simple flag to output just the version:

$ myapp version --simple
v1.0.0

Build-Time Version Injection

Version info is injected at build time via Makefile ldflags:

build: pkg=github.com/your-org/your-app/pkg/version
build: ldflags = -X $(pkg).version=$(shell git describe --tags --always --dirty)
build: ldflags += -X $(pkg).commit=$(shell git rev-parse HEAD)
build: ldflags += -X $(pkg).buildDate=$(shell date -Iseconds)

build: ## Build the application
    @echo "Building $(SERVICE_NAME)..."
    @CGO_ENABLED=0 go build -o $(SERVICE_NAME) -ldflags "$(ldflags)" main.go

To build with a specific version:

Override it directly:

go build -ldflags "-X github.com/your-org/your-app/pkg/version.version=v2.0.0" -o myapp main.go