metadata

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package metadata provides build-time information for CLI applications.

Services set their build variables via ldflags at build time:

go build -ldflags "\
  -X github.com/dioad/cli/metadata.Version=$(VERSION) \
  -X github.com/dioad/cli/metadata.Commit=$(COMMIT) \
  -X github.com/dioad/cli/metadata.Date=$(DATE)" \
  ./...

Then pass a BuildInfo to NewVersionCommand:

cmd.AddCommand(
    metadata.NewVersionCommand(OrgName, AppName, metadata.BuildInfo{
        Version: metadata.Version,
        Commit:  metadata.Commit,
        Date:    metadata.Date,
    }),
)

Index

Constants

This section is empty.

Variables

View Source
var Commit = "XX"

Commit is the git commit SHA, set via ldflags at build time.

View Source
var Date = "1970-01-01"

Date is the build date, set via ldflags at build time.

View Source
var Version = "local"

Version is the application version, set via ldflags at build time.

Functions

func NewVersionCommand

func NewVersionCommand(orgName, appName string, info BuildInfo) *cobra.Command

NewVersionCommand returns a "version" cobra.Command that prints build information. orgName and appName are used in the plain-text output line.

Unlike commands built with cli.NewCommand, this command wires RunE directly and does not call InitConfig, so it produces no side effects such as reading config files, configuring logging, or starting a background WatchConfig goroutine.

Types

type BuildInfo

type BuildInfo struct {
	Version string
	Commit  string
	Date    string
}

BuildInfo holds version information populated at build time.

Jump to

Keyboard shortcuts

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