kongflag

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServiceName    = "service_name"
	ServiceVersion = "service_version"
	GitCommitSHA   = "git_commit_sha"
	GitBranch      = "git_branch"
	GoVersion      = "go_version"
)

Variables

This section is empty.

Functions

func WithBuildInfo

func WithBuildInfo() kong.Option

WithBuildInfo fetches data from debug.BuildInfo and saves it to the kong.Vars

Saved variables:

  • GoVersion ("go_version") – version of Go
  • GitCommitSHA ("git_commit_sha") – SHA of the latest commit

func WithDumpEnvs

func WithDumpEnvs() kong.Option

WithDumpEnvs adds an optional flag '--dump-envs' to the service. If the application is run with this flag, it prints env-vars with default values and exits.

Usage:

ctx := kong.Parse(&app kongflag.WithDumpEnvs())
ctx.FatalIfErrorf(ctx.Run())

CLI usage:

$ go run main.go --dump-envs > example.env

nolint:dupl // False-positive here

func WithVersion

func WithVersion(fallbackVersion string) kong.Option

WithVersion adds an optional flag '--version' to the service. If the application is run with this flag, it prints version and exits.

This option tries to extract version from build info. If it's empty, fallbackVersion is used.

Usage:

ctx := kong.Parse(&app, kongflag.PrintVersionFlag("v1.0.0"))
ctx.FatalIfErrorf(ctx.Run())

CLI usage:

$ go run main.go --version
example version: v1.0.0
 git branch: main
 git revision: 795859ac3599bca75bb417bd0f97303f79289b65
 go: go1.19.5

nolint:dupl,forbidigo // False-positive here

Types

This section is empty.

Jump to

Keyboard shortcuts

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