Documentation
¶
Overview ¶
Package flags provides shared flag helpers for scafctl commands.
Index ¶
- func AddKvxOutputFlags(cmd *cobra.Command, outputFormat *string, interactive *bool, ...)
- func AddKvxOutputFlagsToStruct(cmd *cobra.Command, flags *KvxOutputFlags)
- func AddKvxOutputFlagsWithWhere(cmd *cobra.Command, outputFormat *string, interactive *bool, ...)
- func NewKvxOutputOptionsFromFlags(outputFormat string, interactive bool, expression string, ...) *kvx.OutputOptions
- func RequireArg(argName, example string) cobra.PositionalArgs
- func RequireArgs(n int, argDesc, example string) cobra.PositionalArgs
- func ToKvxOutputOptions(flags *KvxOutputFlags, opts ...kvx.OutputOption) *kvx.OutputOptions
- func ToKvxOutputOptionsFromCmd(cmd *cobra.Command, flags *KvxOutputFlags, opts ...kvx.OutputOption) *kvx.OutputOptions
- func ValidateKvxOutputFormat(format string) error
- type KvxOutputFlags
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddKvxOutputFlags ¶
func AddKvxOutputFlags(cmd *cobra.Command, outputFormat *string, interactive *bool, expression *string)
AddKvxOutputFlags adds kvx-enabled output flags to a command. It sets up the standard -o/--output, -i/--interactive, and -e/--expression flags.
Parameters:
- cmd: The cobra command to add flags to
- outputFormat: Pointer to store the output format value (default: "auto")
- interactive: Pointer to store the interactive mode value (default: false)
- expression: Pointer to store the CEL expression value (default: "")
func AddKvxOutputFlagsToStruct ¶
func AddKvxOutputFlagsToStruct(cmd *cobra.Command, flags *KvxOutputFlags)
AddKvxOutputFlagsToStruct adds kvx-enabled output flags to a command using a KvxOutputFlags struct. This is a convenience function when using the KvxOutputFlags struct directly.
func AddKvxOutputFlagsWithWhere ¶ added in v0.8.0
func AddKvxOutputFlagsWithWhere(cmd *cobra.Command, outputFormat *string, interactive *bool, expression, where *string)
AddKvxOutputFlagsWithWhere adds kvx-enabled output flags including the --where per-item filter. It also registers a PreRunE hook that validates the output format before the command runs.
func NewKvxOutputOptionsFromFlags ¶
func NewKvxOutputOptionsFromFlags( outputFormat string, interactive bool, expression string, opts ...kvx.OutputOption, ) *kvx.OutputOptions
NewKvxOutputOptionsFromFlags creates a new OutputOptions from command flags and options. This is a convenience function that combines flag parsing with functional options.
func RequireArg ¶ added in v0.8.0
func RequireArg(argName, example string) cobra.PositionalArgs
RequireArg returns a cobra.PositionalArgs validator that requires exactly one positional argument. If missing, it returns an error naming the expected argument and showing an example usage. This replaces cobra.ExactArgs(1) with a more descriptive error message.
func RequireArgs ¶ added in v0.8.0
func RequireArgs(n int, argDesc, example string) cobra.PositionalArgs
RequireArgs returns a cobra.PositionalArgs validator that requires exactly n positional arguments with a descriptive error message naming the expected arguments and showing an example.
func ToKvxOutputOptions ¶
func ToKvxOutputOptions(flags *KvxOutputFlags, opts ...kvx.OutputOption) *kvx.OutputOptions
ToKvxOutputOptions converts flag values to OutputOptions for writing output. This creates a fully configured OutputOptions instance from flag values. If the output format is unrecognized, it silently defaults to auto. Use ValidateKvxOutputFormat in the command's RunE to reject invalid formats early.
func ToKvxOutputOptionsFromCmd ¶ added in v0.9.0
func ToKvxOutputOptionsFromCmd(cmd *cobra.Command, flags *KvxOutputFlags, opts ...kvx.OutputOption) *kvx.OutputOptions
ToKvxOutputOptionsFromCmd converts flag values to OutputOptions, auto-detecting whether -o was explicitly set by checking cmd.Flags().Changed("output").
func ValidateKvxOutputFormat ¶
ValidateKvxOutputFormat validates the output format string. Returns an error if the format is not a valid output format.
Types ¶
type KvxOutputFlags ¶
type KvxOutputFlags struct {
// Output specifies the output format (auto, table, list, tree, mermaid, json, yaml, quiet)
Output string `json:"output,omitempty" yaml:"output,omitempty" doc:"Output format" example:"auto" maxLength:"10"`
// Interactive enables the kvx TUI for data exploration
Interactive bool `json:"interactive,omitempty" yaml:"interactive,omitempty" doc:"Launch interactive TUI mode"`
// Expression is a CEL expression to filter/transform output
Expression string `` /* 131-byte string literal not displayed */
// Where is a per-item CEL boolean filter applied to list data
Where string `json:"where,omitempty" yaml:"where,omitempty" doc:"Per-item CEL filter for list data" example:"_.enabled" maxLength:"4096"`
// FormatExplicit is true when the user explicitly set -o on the command line.
// Set automatically by the PreRunE hook via cobra Changed().
FormatExplicit bool `json:"-" yaml:"-"`
// AppName is the binary name shown in table headers and TUI title.
// Not a CLI flag -- set programmatically from settings.Run.BinaryName.
AppName string `json:"-" yaml:"-"`
}
KvxOutputFlags holds the flag values for kvx-enabled output. This struct is typically embedded in command options structs.