cli

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindFlagsFromStruct

func BindFlagsFromStruct(cmd *cobra.Command, opts any) error

BindFlagsFromStruct declares flags based on struct tags. Supported tags: flag, usage, default

func LoadFromCobraFlags

func LoadFromCobraFlags(cmd *cobra.Command, opts any) error

LoadFromCobraFlags reads values of flags defined on cmd according to `flag` tags on the fields of opts (a pointer to struct) and writes them into opts. Supported field kinds: string, bool.

func LoadFromViper

func LoadFromViper(opts any) error

LoadFromViper decodes viper keyspace into the struct. Flags are already bound.

func Preflight

func Preflight(zoneRequired bool) func(cmd *cobra.Command, args []string) error

Preflight returns a PersistentPreRunE-compatible function that ensures login and, if zoneRequired, resolves zoneId via --default-zone or --zoneId flags with consistent error messages.

func SetDefaultZone

func SetDefaultZone(zoneID, zoneName string) error

SetDefaultZone sets the default zone ID and name in the config and writes it to disk.

func TokenFromContext

func TokenFromContext(ctx context.Context) string

func Validate

func Validate(cmd *cobra.Command, rules ...Rule) error

func ZoneIDFromContext

func ZoneIDFromContext(ctx context.Context) string

Types

type CobraValues

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

func NewCobraValues

func NewCobraValues(cmd *cobra.Command) CobraValues

func (CobraValues) Changed

func (c CobraValues) Changed(name string) bool

func (CobraValues) GetBool

func (c CobraValues) GetBool(name string) bool

func (CobraValues) GetString

func (c CobraValues) GetString(name string) string

type FlagSpec

type FlagSpec struct {
	Name  string
	Usage string
	Def   string
}

type Rule

type Rule interface{ Validate(v Values) error }

func ExactlyOne

func ExactlyOne(names ...string) Rule

func IsUlid

func IsUlid(name string) Rule

func MaxLength

func MaxLength(name string, max int) Rule

func MinLength

func MinLength(name string, min int) Rule

func MutuallyExclusive

func MutuallyExclusive(a, b string) Rule

func OneOf

func OneOf(name string, allowed ...string) Rule

func Required

func Required(name string) Rule

func RequiredIf

func RequiredIf(name string, predicate func(v Values) bool) Rule

type RuleFunc

type RuleFunc func(v Values) error

func (RuleFunc) Validate

func (f RuleFunc) Validate(v Values) error

type Values

type Values interface {
	GetString(name string) string
	GetBool(name string) bool
	Changed(name string) bool
}

Jump to

Keyboard shortcuts

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