cobrax

package
v0.0.0-...-152b8de Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 7 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// VersionKey is the annotation key for the raw version.
	VersionKey = "go-utils_version"
	// CommitKey is the annotation key for the commit.
	CommitKey = "go-utils_commit"
)

Variables

View Source
var ErrInvalidShell = errors.New("invalid shell")

Functions

func BuildUserAgent

func BuildUserAgent(cmd *cobra.Command) string

BuildUserAgent generates a value to be used with httpx.UserAgentTransport.

Example output: `example/v1.0.0-deadbeef (linux/amd64)`

func GenCompletion

func GenCompletion(cmd *cobra.Command, shell Shell) error

GenCompletion is a helper function that generates a shell completion script for the provided shell.

func GetCommit

func GetCommit(cmd *cobra.Command) string

GetCommit gets the commit set by WithVersion

func GetVersion

func GetVersion(cmd *cobra.Command) string

GetVersion gets the raw version set by WithVersion

func RegisterCompletionFlag

func RegisterCompletionFlag(cmd *cobra.Command) error

RegisterCompletionFlag registers a flag to generate a shell completion script. Cobra typically uses a subcommand for this, but this flag is useful for executables that don't have any subcommands.

An initializer is registered which will trigger when the flag is set.

Types

type Option

type Option func(cmd *cobra.Command)

func WithVersion

func WithVersion(version string) Option

WithVersion takes a version string and sets the value to a cobra.Command. The current commit will be appended in parentheses, and the raw values will be added to the command's annotations.

type Shell

type Shell string
const (
	FlagCompletion = "completion"

	Bash       Shell = "bash"
	Zsh        Shell = "zsh"
	Fish       Shell = "fish"
	PowerShell Shell = "powershell"
)

Jump to

Keyboard shortcuts

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