Documentation
¶
Index ¶
- Constants
- func AddCommandsToRootCommand(rootCmd *cobra.Command, commands []cmds.Command, aliases []*alias.CommandAlias, ...) error
- func AddGlazedProcessorFlagsToCobraCommand(cmd *cobra.Command, options ...settings.GlazeParameterLayerOption) error
- func BuildCobraCommand(command cmds.Command, opts ...CobraOption) (*cobra.Command, error)
- func BuildCobraCommandAlias(alias *alias.CommandAlias, opts ...CobraOption) (*cobra.Command, error)
- func BuildCobraCommandDualMode(c cmds.Command, _ ...interface{}) (*cobra.Command, error)deprecated
- func BuildCobraCommandFromBareCommand(c cmds.BareCommand, opts ...CobraOption) (*cobra.Command, error)
- func BuildCobraCommandFromCommand(s cmds.Command, opts ...CobraOption) (*cobra.Command, error)
- func BuildCobraCommandFromCommandAndFunc(s cmds.Command, run CobraRunFunc, opts ...CobraOption) (*cobra.Command, error)
- func BuildCobraCommandFromGlazeCommand(cmd_ cmds.GlazeCommand, opts ...CobraOption) (*cobra.Command, error)deprecated
- func BuildCobraCommandFromWriterCommand(s cmds.WriterCommand, opts ...CobraOption) (*cobra.Command, error)deprecated
- func CobraCommandDefaultMiddlewares(parsedCommandLayers *layers.ParsedLayers, cmd *cobra.Command, args []string) ([]cmd_middlewares.Middleware, error)
- func CreateGlazedProcessorFromCobra(cmd *cobra.Command) (*middlewares.TableProcessor, formatters.OutputFormatter, error)
- func GetVerbsFromCobraCommand(cmd *cobra.Command) []string
- func NewCobraCommandFromCommandDescription(description *cmds.CommandDescription) *cobra.Command
- func NewCommandSettingsLayer() (layers.ParameterLayer, error)
- func NewCreateCommandSettingsLayer() (layers.ParameterLayer, error)
- func NewProfileSettingsLayer() (layers.ParameterLayer, error)
- func ParseCommandSettingsLayer(cmd *cobra.Command) (*layers.ParsedLayers, error)
- type CobraMiddlewaresFunc
- type CobraOption
- func WithCobraMiddlewaresFunc(fn CobraMiddlewaresFunc) CobraOption
- func WithCobraShortHelpLayers(layers ...string) CobraOption
- func WithCreateCommandSettingsLayer() CobraOption
- func WithDefaultToGlaze() CobraOption
- func WithDualMode(enabled bool) CobraOption
- func WithGlazeToggleFlag(name string) CobraOption
- func WithHiddenGlazeFlags(names ...string) CobraOption
- func WithParserConfig(cfg CobraParserConfig) CobraOption
- func WithProfileSettingsLayer() CobraOption
- func WithSkipCommandSettingsLayer() CobraOption
- type CobraParser
- type CobraParserConfig
- type CobraRunFunc
- type CommandSettings
- type CreateCommandSettings
- type ProfileSettings
Constants ¶
const CommandSettingsSlug = "command-settings"
const CreateCommandSettingsSlug = "create-command-settings"
const ProfileSettingsSlug = "profile-settings"
Variables ¶
This section is empty.
Functions ¶
func AddCommandsToRootCommand ¶ added in v0.2.10
func AddCommandsToRootCommand( rootCmd *cobra.Command, commands []cmds.Command, aliases []*alias.CommandAlias, opts ...CobraOption, ) error
func AddGlazedProcessorFlagsToCobraCommand ¶ added in v0.2.10
func AddGlazedProcessorFlagsToCobraCommand(cmd *cobra.Command, options ...settings.GlazeParameterLayerOption) error
AddGlazedProcessorFlagsToCobraCommand is a helper for cobra centric apps that quickly want to add the glazed processing layer to their CLI flags.
func BuildCobraCommand ¶ added in v0.2.10
BuildCobraCommand is an alias to help with LLM hallucinations
func BuildCobraCommandAlias ¶ added in v0.2.10
func BuildCobraCommandAlias( alias *alias.CommandAlias, opts ...CobraOption, ) (*cobra.Command, error)
func BuildCobraCommandFromBareCommand ¶ added in v0.2.69
func BuildCobraCommandFromBareCommand(c cmds.BareCommand, opts ...CobraOption) (*cobra.Command, error)
Deprecated wrappers for backwards compatibility with earlier APIs Use BuildCobraCommand or BuildCobraCommand from the unified API instead. Deprecated: use BuildCobraCommand(c, opts...)
func BuildCobraCommandFromCommand ¶ added in v0.2.47
Unified builder: determines runFunc based on implemented interfaces and delegates to BuildCobraCommandFromCommandAndFunc
func BuildCobraCommandFromCommandAndFunc ¶ added in v0.4.3
func BuildCobraCommandFromCommandAndFunc( s cmds.Command, run CobraRunFunc, opts ...CobraOption, ) (*cobra.Command, error)
func BuildCobraCommandFromGlazeCommand
deprecated
added in
v0.2.46
func BuildCobraCommandFromGlazeCommand(cmd_ cmds.GlazeCommand, opts ...CobraOption) (*cobra.Command, error)
Deprecated: use BuildCobraCommand(c, opts...)
func BuildCobraCommandFromWriterCommand
deprecated
added in
v0.2.47
func BuildCobraCommandFromWriterCommand(s cmds.WriterCommand, opts ...CobraOption) (*cobra.Command, error)
Deprecated: use BuildCobraCommand(c, opts...)
func CobraCommandDefaultMiddlewares ¶ added in v0.4.36
func CobraCommandDefaultMiddlewares( parsedCommandLayers *layers.ParsedLayers, cmd *cobra.Command, args []string, ) ([]cmd_middlewares.Middleware, error)
CobraCommandDefaultMiddlewares is the default implementation for creating the middlewares used in a Cobra command. It handles parsing parameters from Cobra flags, command line arguments, environment variables, and default values. The middlewares gather all these parameters into a ParsedParameters object.
If the commandSettings specify parameters to be loaded from a file, this gets added as a middleware.
func CreateGlazedProcessorFromCobra ¶ added in v0.2.10
func CreateGlazedProcessorFromCobra(cmd *cobra.Command) (*middlewares.TableProcessor, formatters.OutputFormatter, error)
CreateGlazedProcessorFromCobra is a helper for cobra centric apps that quickly want to add the glazed processing layer.
If you are more serious about using glazed, consider using the `cmds.GlazeCommand` and `parameters.ParameterDefinition` abstraction to define your CLI applications, which allows you to use Layers and other nice features of the glazed ecosystem.
If so, use SetupTableProcessor instead, and create a proper glazed.GlazeCommand for your command.
func GetVerbsFromCobraCommand ¶ added in v0.2.55
func NewCobraCommandFromCommandDescription ¶ added in v0.5.3
func NewCobraCommandFromCommandDescription( description *cmds.CommandDescription, ) *cobra.Command
func NewCommandSettingsLayer ¶ added in v0.5.29
func NewCommandSettingsLayer() (layers.ParameterLayer, error)
func NewCreateCommandSettingsLayer ¶ added in v0.5.29
func NewCreateCommandSettingsLayer() (layers.ParameterLayer, error)
func NewProfileSettingsLayer ¶ added in v0.5.29
func NewProfileSettingsLayer() (layers.ParameterLayer, error)
func ParseCommandSettingsLayer ¶ added in v0.5.29
func ParseCommandSettingsLayer(cmd *cobra.Command) (*layers.ParsedLayers, error)
ParseGlazedCommandLayer parses the global glazed settings from the given cobra.Command, if not nil, and from the configured viper config file.
Types ¶
type CobraMiddlewaresFunc ¶ added in v0.4.36
type CobraMiddlewaresFunc func( parsedCommandLayers *layers.ParsedLayers, cmd *cobra.Command, args []string, ) ([]cmd_middlewares.Middleware, error)
CobraMiddlewaresFunc is a function that returns a list of middlewares for a cobra command. It can be used to overload the default middlewares for cobra commands. It is mostly used to add a "load from json" layer set in the GlazedCommandSettings.
type CobraOption ¶ added in v0.6.7
type CobraOption func(cfg *commandBuildConfig)
Insert foundation types for unified builder options CobraOption configures command and parser builder settings
func WithCobraMiddlewaresFunc ¶ added in v0.4.36
func WithCobraMiddlewaresFunc(fn CobraMiddlewaresFunc) CobraOption
WithCobraMiddlewaresFunc sets a custom middleware function for parsing (deprecated)
func WithCobraShortHelpLayers ¶ added in v0.5.6
func WithCobraShortHelpLayers(layers ...string) CobraOption
Backwards compatibility helpers for old parser options WithCobraShortHelpLayers sets the layers shown in short help (deprecated)
func WithCreateCommandSettingsLayer ¶ added in v0.5.29
func WithCreateCommandSettingsLayer() CobraOption
WithCreateCommandSettingsLayer enables the create-command settings layer (deprecated)
func WithDefaultToGlaze ¶ added in v0.6.2
func WithDefaultToGlaze() CobraOption
WithDefaultToGlaze makes glaze mode the default unless negated
func WithDualMode ¶ added in v0.6.7
func WithDualMode(enabled bool) CobraOption
WithDualMode enables or disables dual-mode behavior
func WithGlazeToggleFlag ¶ added in v0.6.2
func WithGlazeToggleFlag(name string) CobraOption
WithGlazeToggleFlag customizes the glaze toggle flag name
func WithHiddenGlazeFlags ¶ added in v0.6.2
func WithHiddenGlazeFlags(names ...string) CobraOption
WithHiddenGlazeFlags marks glaze flags to remain hidden
func WithParserConfig ¶ added in v0.6.7
func WithParserConfig(cfg CobraParserConfig) CobraOption
WithParserConfig sets parser customization on the builder
func WithProfileSettingsLayer ¶ added in v0.5.29
func WithProfileSettingsLayer() CobraOption
WithProfileSettingsLayer enables the profile settings layer (deprecated)
func WithSkipCommandSettingsLayer ¶ added in v0.5.29
func WithSkipCommandSettingsLayer() CobraOption
WithSkipCommandSettingsLayer hides the command settings layer flags (deprecated)
type CobraParser ¶ added in v0.2.46
type CobraParser struct { Layers *layers.ParameterLayers // contains filtered or unexported fields }
CobraParser takes a CommandDescription, and hooks it up to a cobra command. It can then be used to parse the cobra flags and arguments back into a set of ParsedLayer and a map[string]interface{} for the lose stuff.
That command however doesn't have a Run* method, which is left to the caller to implement.
This returns a CobraParser that can be used to parse the registered Layers from the description.
func NewCobraParserFromLayers ¶ added in v0.5.3
func NewCobraParserFromLayers( layers *layers.ParameterLayers, cfg *CobraParserConfig, ) (*CobraParser, error)
NewCobraParserFromLayers creates a new CobraParser instance from a CommandDescription, initializes the underlying cobra.Command, and adds all the parameters specified in the Layers CommandDescription to the cobra command.
func (*CobraParser) AddToCobraCommand ¶ added in v0.5.3
func (c *CobraParser) AddToCobraCommand(cmd *cobra.Command) error
func (*CobraParser) Parse ¶ added in v0.2.46
func (c *CobraParser) Parse( cmd *cobra.Command, args []string, ) (*layers.ParsedLayers, error)
type CobraParserConfig ¶ added in v0.6.7
type CobraParserConfig struct { MiddlewaresFunc CobraMiddlewaresFunc ShortHelpLayers []string SkipCommandSettingsLayer bool EnableProfileSettingsLayer bool EnableCreateCommandSettingsLayer bool }
Inserted: new config struct for parser customization
type CobraRunFunc ¶ added in v0.2.47
type CobraRunFunc func(ctx context.Context, parsedLayers *layers.ParsedLayers) error
type CommandSettings ¶ added in v0.5.29
type CommandSettings struct { PrintYAML bool `glazed.parameter:"print-yaml"` PrintParsedParameters bool `glazed.parameter:"print-parsed-parameters"` LoadParametersFromFile string `glazed.parameter:"load-parameters-from-file"` PrintSchema bool `glazed.parameter:"print-schema"` }
GlazedMinimalCommandSettings contains a subset of the most commonly used settings