format

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2025 License: Unlicense Imports: 10 Imported by: 0

Documentation

Index

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 HelpFmt

func HelpFmt[T any](a *T) string

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

func ValidateFlags[T comparable](rules map[string][]T) func(*cobra.Command, []string) error

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...).

func WriteJSON

func WriteJSON(v any, w io.Writer)

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) String

func (f *FormatType) String() string

String implements pflag.Value.

func (*FormatType) Type

func (f *FormatType) Type() string

Type implements pflag.Value (required by cobra/pflag for help output).

Jump to

Keyboard shortcuts

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