Documentation
¶
Index ¶
- func Format(f FormatType, o ...any)
- func HelpFmt[T any](a *T) string
- func OutputFmtFlagUsage(allowedFormats []FormatType) string
- func UpdateUsageAndAssertContains(o *pflag.Flag, allowedFormats []FormatType) error
- func ValidateFlags[T comparable](rules map[string][]T) func(*cobra.Command, []string) error
- func WriteJSON(v any, w io.Writer)
- type CobraPFlagParams
- type FormatType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Format ¶
func Format(f FormatType, o ...any)
Format formats the output according to the given format.
func OutputFmtFlagUsage ¶
func OutputFmtFlagUsage(allowedFormats []FormatType) string
allowedFormats := []f.FormatType{f.FormatJSON} format := apiCmd.Flag("format")
if format == nil {
panic("FORMAT")
}
format.Usage = "output format. One of: "+f.HelpFmt(&allowedFormats)
func UpdateUsageAndAssertContains ¶
func UpdateUsageAndAssertContains(o *pflag.Flag, allowedFormats []FormatType) error
o outputFormat updates o.Usage and validates..
func ValidateFlags ¶
ValidateFlags returns a PersistentPreRunE that validates flag values against pre-defined sets of allowed values. It uses generics so the allowed slice can be any comparable type (string, int, custom enums...).
Types ¶
type CobraPFlagParams ¶
type CobraPFlagParams struct {
// P is the pointer to the string variable that will hold the flag's value.
P *string
// Name is the long name of the flag.
Name string
// Shorthand is the single‑character abbreviation.
Shorthand string
// Value is the default value for the flag.
Value string
// Usage describes the purpose of the flag.
Usage string
}
TODO: move this somewhere else misses flag set
type FormatType ¶
type FormatType string
FormatType defines the allowed formats for the Format function. it implements pflag.VarP
const (
FormatJSON FormatType = "json"
)
func (*FormatType) Set ¶
func (f *FormatType) Set(val string) error
Set implements pflag.Value. It validates and sets the format.
func (*FormatType) Type ¶
func (f *FormatType) Type() string
Type implements pflag.Value (required by cobra/pflag for help output).