version

package
v0.0.0-...-b125894 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package version centralizes CLI build/version metadata across cmd/*. It mirrors kubectl's version.Info schema so downstream tooling can parse the JSON form interchangeably.

Index

Constants

View Source
const Devel = "(devel)"

Devel is the placeholder used when no value is injected via -ldflags and runtime/debug.ReadBuildInfo cannot supply one (e.g. `go run`, `go test`, ad-hoc local builds).

Variables

This section is empty.

Functions

This section is empty.

Types

type Info

type Info struct {
	Name         string `json:"name"`
	Version      string `json:"version"`
	GitCommit    string `json:"git_commit"`
	GitTreeState string `json:"git_tree_state"`
	BuildTime    string `json:"build_time"`
	GoVersion    string `json:"go_version"`
	Compiler     string `json:"compiler"`
	Platform     string `json:"platform"`
}

Info captures CLI release identity. Field order mirrors kubectl's version.Info to ease integration with downstream tooling.

func Resolve

func Resolve(s Seed) Info

Resolve returns Info populated from Seed first, then runtime/debug, then runtime constants. Missing string values fall back to Devel so callers always get a renderable value.

func Wire

func Wire(app *cli.App, s Seed) Info

Wire resolves Seed, sets app.Version to the multi-line form, registers the global --version-format flag (text|json|short), and overrides cli.VersionPrinter so `-v` honors the chosen format. Returns the resolved Info so callers can reuse it (e.g. as a toolstream version).

It also chains app.Before to warn when --version-format is set but --version is not, since the format flag has no effect on its own.

Must be called after the caller has populated app.Flags, since Wire appends to that slice.

func (*Info) JSON

func (i *Info) JSON() string

JSON returns the canonical indented JSON serialization.

func (*Info) Labels

func (i *Info) Labels() map[string]string

Labels returns an independent set of build identity labels using the JSON keys.

func (*Info) Multiline

func (i *Info) Multiline() string

Multiline returns a kubectl-style multi-line block, suitable as urfave/cli's app.Version output.

func (*Info) Short

func (i *Info) Short() string

Short returns "<name> <version> (<short-commit>[-dirty])".

type Seed

type Seed struct {
	Name      string
	Version   string
	GitCommit string
	BuildTime string
}

Seed carries values injected by the Makefile via -ldflags -X. Empty fields are backfilled from runtime/debug.ReadBuildInfo when available.

Jump to

Keyboard shortcuts

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