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 ¶
var Commit = "XX"
Commit is the git commit SHA, set via ldflags at build time.
var Date = "1970-01-01"
Date is the build date, set via ldflags at build time.
var Version = "local"
Version is the application version, set via ldflags at build time.
Functions ¶
func NewVersionCommand ¶
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.