king

package module
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2023 License: MIT Imports: 20 Imported by: 5

README

king

See _example/main.go on how to use it.

Documentation

Overview

Package king is a library to configure the command line parser https://github.com/alecthomas/kong

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Configs

func Configs(vars kong.Vars) []string

Configs returns all configured absolute paths form kong.Vars.

func DefaultOptions

func DefaultOptions(c Config) []kong.Option

DefaultOptions creates a set of opinionated options.

func EnvResolver

func EnvResolver() kong.Resolver

EnvResolver returns a Resolver that retrieves values from environment variables.

Hyphens in flag names are replaced with underscores. Flag names are prefixed with app name and converted to uppercase.

Usage:
ctx := kong.Parse(&cli,
    kong.Resolvers(pfkong.EnvResolver()),
    )
}

func NewFileResolver added in v0.2.0

func NewFileResolver(f FileResolver) kong.ConfigurationLoader

NewFileResolver creates a new fileresolver.

Types

type BuildInfo

type BuildInfo struct {
	// contains filtered or unexported fields
}

BuildInfo represents build information.

func NewBuildInfo

func NewBuildInfo(version string, opts ...Option) (*BuildInfo, error)

NewBuildInfo creates BuildInformation from version, revision and date. These values are typically set with ldflags (via goreleaser for example).

The date has to be in time.RFC3339 format and the revision must be at least 8 chars long.

func (*BuildInfo) Version

func (b *BuildInfo) Version(program string) Version

Version returns the version information.

type Config

type Config struct {
	Context      context.Context
	Name         string
	Description  string
	BuildInfo    *BuildInfo
	ConfigPaths  []string
	Variables    map[string]string
	FileResolver FileResolver
}

Config is used to create DefaultOptions.

type FileResolver added in v0.2.0

type FileResolver string

FileResolver represents a kong fileresolver.

const (
	YAML FileResolver = "yaml"
	TOML FileResolver = "toml"
)

All supported file resolvers.

type Map

type Map map[string]interface{}

Map is a map with string as key and interface{} as value.

func FlagMap

func FlagMap(ctx *kong.Context, redactFlags ...*regexp.Regexp) Map

FlagMap returns the flags and corresponding values from *kong.Context.

To prevent logging sensitive flag values it is possible to provide a list of regular expressions. Flag values of flag names that match are redacted by '*'.

func (Map) Add

func (m Map) Add(keyVals ...string) Map

Add adds key and values.

func (Map) List

func (m Map) List() []interface{}

List returns the flag and values as list (sorted by keys).

func (Map) Register

func (m Map) Register(program string, registerer prometheus.Registerer) Map

Register registers prometheus flag collectors that display configured flags as metrics. The genereated metrics are of the form:

kong_flag{program="progname", name="flagname", value="flagvalue"} 1

func (Map) Rm

func (m Map) Rm(keys ...string) Map

Rm removes keys from Map.

type Option

type Option func(*BuildInfo) error

Option is a BuildInfo functional option.

func WithDate

func WithDate(date time.Time) Option

WithDate sets the build date.

func WithDateString

func WithDateString(date string) Option

WithDateString sets the build date (RFC3339).

func WithLocation

func WithLocation(loc string) Option

WithLocation sets the timezone for the build date.

func WithRevision

func WithRevision(r string) Option

WithRevision sets the git commit revision.

type ShowConfig

type ShowConfig bool

ShowConfig can be used to show information about the parsed configuration files.

func (ShowConfig) BeforeApply

func (s ShowConfig) BeforeApply(app *kong.Kong, vars kong.Vars) error

BeforeApply is the actual show-config command.

type Version added in v0.3.0

type Version struct {
	Version   string `json:"version" yaml:"version"`
	Revision  string `json:"revision" yaml:"revision"`
	Date      string `json:"date" yaml:"date"`
	GoVersion string `json:"go_version" yaml:"go_version"`
	Program   string `json:"program" yaml:"program"`
}

Version represents the version of a go program.

func (Version) String added in v0.3.0

func (v Version) String() string

type VersionFlag

type VersionFlag bool

VersionFlag displays the version information stored in "version" key form kong.Vars.

Use this flag to show version information.

func (VersionFlag) BeforeApply

func (v VersionFlag) BeforeApply(app *kong.Kong, vars kong.Vars) error

BeforeApply is the actual version command.

Directories

Path Synopsis
cmd
Package cmd represents the command.
Package cmd represents the command.

Jump to

Keyboard shortcuts

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