Documentation ¶
Index ¶
- func AddFlagGroupToCobraCommand(cmd *cobra.Command, id string, name string, ...)
- func SetFlagGroupOrder(cmd *cobra.Command, order []string)
- type CommandFlagGroupUsage
- type FlagGroup
- type FlagGroupUsage
- type FlagUsage
- type ParameterLayer
- type ParameterLayerImpl
- func (p *ParameterLayerImpl) AddFlag(flag *parameters.ParameterDefinition)
- func (p *ParameterLayerImpl) AddFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) error
- func (p *ParameterLayerImpl) GetDescription() string
- func (p *ParameterLayerImpl) GetName() string
- func (p *ParameterLayerImpl) GetParameterDefinitions() map[string]*parameters.ParameterDefinition
- func (p *ParameterLayerImpl) GetSlug() string
- func (p *ParameterLayerImpl) InitializeParameterDefaultsFromStruct(defaults interface{}) error
- func (p *ParameterLayerImpl) InitializeParameterDefinitionsFromParameters(ps map[string]interface{}) error
- func (p *ParameterLayerImpl) InitializeStructFromParameterDefaults(s interface{}) error
- func (p *ParameterLayerImpl) LoadFromYAML(s []byte) error
- func (p *ParameterLayerImpl) ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)
- func (p *ParameterLayerImpl) UnmarshalYAML(unmarshal func(interface{}) error) error
- type ParameterLayerOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddFlagGroupToCobraCommand ¶
func AddFlagGroupToCobraCommand(cmd *cobra.Command, id string, name string, flags []*parameters.ParameterDefinition)
func SetFlagGroupOrder ¶
Types ¶
type CommandFlagGroupUsage ¶
type CommandFlagGroupUsage struct { LocalGroupUsages []*FlagGroupUsage InheritedGroupUsages []*FlagGroupUsage }
CommandFlagGroupUsage is used to render the flags for an entire command. This gets parsed at rendering time, and passed along the command to the usage or help template. Flags that are not assigned to any group are passed as the "" group, with the name "Other flags".
func ComputeCommandFlagGroupUsage ¶
func ComputeCommandFlagGroupUsage(c *cobra.Command) *CommandFlagGroupUsage
func (*CommandFlagGroupUsage) String ¶
func (c *CommandFlagGroupUsage) String() string
type FlagGroup ¶
FlagGroup is a group of flags that can be added to a cobra command. While we mostly deal with ParameterDefinitions, this uses strings because it can be applied to any cobra flag in general.
It limits us in the sense that we can't just get the full ParameterDefinition here, but at least we can format our help a little bit more nicely.
NOTE(manuel, 2023-02-20) This doesn't allow for hierarchical flag groups yet. Let's see how this feels overall, and if this is something we want to add later on. This is useful I think because subsystems such as glaze already pull in so many flags, and it could be used in conjunction with renaming the actual flags used on the CLI as more colisions are prone to happen.
func GetFlagGroups ¶
type FlagGroupUsage ¶
FlagGroupUsage is used to render the help for a flag group. It consists of the group Name for rendering purposes, and a single string per flag in the group
func (*FlagGroupUsage) AddFlagUsage ¶
func (f *FlagGroupUsage) AddFlagUsage(flag *FlagUsage)
func (*FlagGroupUsage) String ¶
func (f *FlagGroupUsage) String() string
type FlagUsage ¶
FlagUsage is the structured information we want to show at help time. Instead of rendering the full time, we leave how these things are formatted all the way to the end, because for example aligning strings can only be done at runtime since we don't know which other flags might have been added to the one group.
type ParameterLayer ¶
type ParameterLayer interface { AddFlag(flag *parameters.ParameterDefinition) GetParameterDefinitions() map[string]*parameters.ParameterDefinition InitializeStructFromParameterDefaults(s interface{}) error InitializeParameterDefaultsFromStruct(s interface{}) error AddFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) error ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error) GetName() string GetSlug() string GetDescription() string }
type ParameterLayerImpl ¶
type ParameterLayerImpl struct { Name string `yaml:"name"` Slug string `yaml:"slug"` Description string `yaml:"description"` Flags []*parameters.ParameterDefinition `yaml:"flags,omitempty"` }
func NewParameterLayer ¶
func NewParameterLayer(slug string, name string, options ...ParameterLayerOptions) *ParameterLayerImpl
func NewParameterLayerFromYAML ¶
func NewParameterLayerFromYAML(s []byte) (*ParameterLayerImpl, error)
func (*ParameterLayerImpl) AddFlag ¶
func (p *ParameterLayerImpl) AddFlag(flag *parameters.ParameterDefinition)
func (*ParameterLayerImpl) AddFlagsToCobraCommand ¶
func (p *ParameterLayerImpl) AddFlagsToCobraCommand(cmd *cobra.Command, defaults interface{}) error
func (*ParameterLayerImpl) GetDescription ¶ added in v0.2.13
func (p *ParameterLayerImpl) GetDescription() string
func (*ParameterLayerImpl) GetName ¶ added in v0.2.13
func (p *ParameterLayerImpl) GetName() string
func (*ParameterLayerImpl) GetParameterDefinitions ¶
func (p *ParameterLayerImpl) GetParameterDefinitions() map[string]*parameters.ParameterDefinition
GetParameterDefinitions returns a map that maps all parameters (flags and arguments) to their name. I'm not sure if this is worth caching, but if we hook this up like something like a lambda that might become more relevant.
func (*ParameterLayerImpl) GetSlug ¶ added in v0.2.13
func (p *ParameterLayerImpl) GetSlug() string
func (*ParameterLayerImpl) InitializeParameterDefaultsFromStruct ¶ added in v0.2.13
func (p *ParameterLayerImpl) InitializeParameterDefaultsFromStruct(defaults interface{}) error
InitializeParameterDefaultsFromStruct initializes the `ParameterDefinition` of the layer, which are often defined at compile time and loaded from a YAML file, with fresh ones from the struct. This is in some ways the opposite of `InitializeStructFromParameterDefaults`. The struct fields of `defaults` with a struct tag of `glazed.parameter` are used to initialize the `ParameterDefinition` with a matching name. If no matching `ParameterDefinition` is found, an error is returned.
func (*ParameterLayerImpl) InitializeParameterDefinitionsFromParameters ¶ added in v0.2.13
func (p *ParameterLayerImpl) InitializeParameterDefinitionsFromParameters( ps map[string]interface{}, ) error
func (*ParameterLayerImpl) InitializeStructFromParameterDefaults ¶ added in v0.2.13
func (p *ParameterLayerImpl) InitializeStructFromParameterDefaults(s interface{}) error
func (*ParameterLayerImpl) LoadFromYAML ¶
func (p *ParameterLayerImpl) LoadFromYAML(s []byte) error
func (*ParameterLayerImpl) ParseFlagsFromCobraCommand ¶
func (p *ParameterLayerImpl) ParseFlagsFromCobraCommand(cmd *cobra.Command) (map[string]interface{}, error)
func (*ParameterLayerImpl) UnmarshalYAML ¶
func (p *ParameterLayerImpl) UnmarshalYAML(unmarshal func(interface{}) error) error
type ParameterLayerOptions ¶
type ParameterLayerOptions func(*ParameterLayerImpl)
func WithDescription ¶
func WithDescription(description string) ParameterLayerOptions
func WithFlags ¶
func WithFlags(flags ...*parameters.ParameterDefinition) ParameterLayerOptions