Documentation ¶
Index ¶
- func GetParentsFromDir(dir string, cmdRoot string) []string
- type Command
- type CommandAlias
- type CommandDescription
- type CommandDescriptionOption
- func WithArguments(a ...*parameters.ParameterDefinition) CommandDescriptionOption
- func WithFlags(f ...*parameters.ParameterDefinition) CommandDescriptionOption
- func WithLayers(l ...layers.ParameterLayer) CommandDescriptionOption
- func WithLong(s string) CommandDescriptionOption
- func WithName(s string) CommandDescriptionOption
- func WithParents(p ...string) CommandDescriptionOption
- func WithPrependParents(p ...string) CommandDescriptionOption
- func WithPrependSource(s string) CommandDescriptionOption
- func WithReplaceArguments(args ...*parameters.ParameterDefinition) CommandDescriptionOption
- func WithReplaceFlags(flags ...*parameters.ParameterDefinition) CommandDescriptionOption
- func WithReplaceLayers(layers_ ...layers.ParameterLayer) CommandDescriptionOption
- func WithShort(s string) CommandDescriptionOption
- func WithSource(s string) CommandDescriptionOption
- func WithStripParentsPrefix(prefixes []string) CommandDescriptionOption
- type ExitWithoutGlazeError
- type FSCommandLoader
- type GlazeProcessor
- type Processor
- type SimpleGlazeProcessor
- type YAMLCommandLoader
- type YAMLFSCommandLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetParentsFromDir ¶ added in v0.2.27
GetParentsFromDir is a helper function to simply return a list of parent verbs for applications loaded from declarative yaml files. The directory structure mirrors the verb structure in cobra.
Types ¶
type Command ¶
type Command interface { // Run is called to actually execute the command. // // NOTE(manuel, 2023-02-27) We can probably simplify this to only take parsed layers // // The ps and GlazeProcessor calls could be replaced by a Command specific layer, // which would allow the Command to parse into a specific struct. The GlazeProcessor // is just something created by the passed in GlazeLayer anyway. // // When we are just left with building a convenience wrapper for Glaze based commands, // instead of forcing it into the upstream interface. // // See https://github.com/go-go-golems/glazed/issues/173 // // NOTE(manuel, 2023-02-21) Does a command always need a GlazeProcessor? // // If we allow it to be passed as a parameter, we can have the caller configure // the formatter to our needs, even if many of the flags might actually be in the parameters // list itself. This makes it easy to hook things up as always JSON when used in an API, // for example? Run( ctx context.Context, parsedLayers map[string]*layers.ParsedParameterLayer, ps map[string]interface{}, gp Processor, ) error Description() *CommandDescription }
type CommandAlias ¶
type CommandAlias struct { Name string `yaml:"name"` AliasFor string `yaml:"aliasFor"` Flags map[string]string `yaml:"flags,omitempty"` Arguments []string `yaml:"arguments,omitempty"` AliasedCommand Command `yaml:",omitempty"` Parents []string `yaml:",omitempty"` Source string `yaml:",omitempty"` }
CommandAlias defines a struct that should be able to define generic aliases for any kind of command line applications, by providing overrides for certain flags (prepopulating them with certain flags and arguments, basically)
func LoadCommandAliasFromYAML ¶ added in v0.2.5
func LoadCommandAliasFromYAML(s io.Reader) ([]*CommandAlias, error)
func (*CommandAlias) Description ¶
func (a *CommandAlias) Description() *CommandDescription
Description returns the CommandDescription of an alias. It computes it at runtime by loading the aliased command's Description() and making copies of its flags and arguments. This is necessary because they get mutated at runtime with various defaults, depending on where they come from.
func (*CommandAlias) IsValid ¶
func (a *CommandAlias) IsValid() bool
func (*CommandAlias) Run ¶
func (a *CommandAlias) Run( ctx context.Context, parsedLayers map[string]*layers.ParsedParameterLayer, ps map[string]interface{}, gp Processor, ) error
func (*CommandAlias) String ¶ added in v0.2.5
func (a *CommandAlias) String() string
type CommandDescription ¶
type CommandDescription struct { Name string `yaml:"name"` Short string `yaml:"short"` Long string `yaml:"long,omitempty"` Flags []*parameters.ParameterDefinition `yaml:"flags,omitempty"` Arguments []*parameters.ParameterDefinition `yaml:"arguments,omitempty"` Layers []layers.ParameterLayer `yaml:"layers,omitempty"` Parents []string `yaml:",omitempty"` // Source indicates where the command was loaded from, to make debugging easier. Source string `yaml:",omitempty"` }
CommandDescription contains the necessary information for registering a command with cobra. Because a command gets registered in a verb tree, a full list of Parents all the way to the root needs to be provided.
func NewCommandDescription ¶ added in v0.2.10
func NewCommandDescription(name string, options ...CommandDescriptionOption) *CommandDescription
func (*CommandDescription) Clone ¶ added in v0.2.25
func (c *CommandDescription) Clone(cloneFlagsAndArguments bool, options ...CommandDescriptionOption) *CommandDescription
type CommandDescriptionOption ¶ added in v0.2.10
type CommandDescriptionOption func(*CommandDescription)
func WithArguments ¶ added in v0.2.10
func WithArguments(a ...*parameters.ParameterDefinition) CommandDescriptionOption
func WithFlags ¶ added in v0.2.10
func WithFlags(f ...*parameters.ParameterDefinition) CommandDescriptionOption
func WithLayers ¶ added in v0.2.10
func WithLayers(l ...layers.ParameterLayer) CommandDescriptionOption
func WithLong ¶ added in v0.2.10
func WithLong(s string) CommandDescriptionOption
func WithName ¶ added in v0.2.25
func WithName(s string) CommandDescriptionOption
func WithParents ¶ added in v0.2.10
func WithParents(p ...string) CommandDescriptionOption
func WithPrependParents ¶ added in v0.2.27
func WithPrependParents(p ...string) CommandDescriptionOption
func WithPrependSource ¶ added in v0.2.27
func WithPrependSource(s string) CommandDescriptionOption
func WithReplaceArguments ¶ added in v0.2.25
func WithReplaceArguments(args ...*parameters.ParameterDefinition) CommandDescriptionOption
func WithReplaceFlags ¶ added in v0.2.25
func WithReplaceFlags(flags ...*parameters.ParameterDefinition) CommandDescriptionOption
func WithReplaceLayers ¶ added in v0.2.25
func WithReplaceLayers(layers_ ...layers.ParameterLayer) CommandDescriptionOption
func WithShort ¶ added in v0.2.10
func WithShort(s string) CommandDescriptionOption
func WithSource ¶ added in v0.2.10
func WithSource(s string) CommandDescriptionOption
func WithStripParentsPrefix ¶ added in v0.2.27
func WithStripParentsPrefix(prefixes []string) CommandDescriptionOption
type ExitWithoutGlazeError ¶ added in v0.2.16
type ExitWithoutGlazeError struct{}
func (*ExitWithoutGlazeError) Error ¶ added in v0.2.16
func (e *ExitWithoutGlazeError) Error() string
type FSCommandLoader ¶ added in v0.2.5
type FSCommandLoader interface {
LoadCommandsFromFS(f fs.FS, dir string, options ...CommandDescriptionOption) ([]Command, []*CommandAlias, error)
}
FSCommandLoader is an interface that describes the most generic loader type, which is then used to load commands and command aliases from embedded queries and from "repository" directories used by glazed.
Examples of this pattern are used in sqleton, escuse-me and pinocchio.
type GlazeProcessor ¶ added in v0.2.6
type GlazeProcessor struct {
// contains filtered or unexported fields
}
func NewGlazeProcessor ¶ added in v0.2.6
func NewGlazeProcessor(of formatters.OutputFormatter, oms ...middlewares.ObjectMiddleware) *GlazeProcessor
func (*GlazeProcessor) OutputFormatter ¶ added in v0.2.6
func (gp *GlazeProcessor) OutputFormatter() formatters.OutputFormatter
func (*GlazeProcessor) ProcessInputObject ¶ added in v0.2.6
func (gp *GlazeProcessor) ProcessInputObject(obj map[string]interface{}) error
TODO(2022-12-18, manuel) we should actually make it possible to order the columns https://github.com/go-go-golems/glazed/issues/56
type Processor ¶ added in v0.2.25
type Processor interface { ProcessInputObject(obj map[string]interface{}) error OutputFormatter() formatters.OutputFormatter }
type SimpleGlazeProcessor ¶ added in v0.2.25
type SimpleGlazeProcessor struct { *GlazeProcessor // contains filtered or unexported fields }
SimpleGlazeProcessor only collects the output and returns it as a types.Table
func NewSimpleGlazeProcessor ¶ added in v0.2.25
func NewSimpleGlazeProcessor(oms ...middlewares.ObjectMiddleware) *SimpleGlazeProcessor
func (*SimpleGlazeProcessor) GetTable ¶ added in v0.2.25
func (gp *SimpleGlazeProcessor) GetTable() *types.Table
type YAMLCommandLoader ¶ added in v0.2.5
type YAMLCommandLoader interface { LoadCommandFromYAML(s io.Reader, options ...CommandDescriptionOption) ([]Command, error) LoadCommandAliasFromYAML(s io.Reader) ([]*CommandAlias, error) }
YAMLCommandLoader is an interface that allows an application using the glazed library to loader commands from YAML files.
type YAMLFSCommandLoader ¶ added in v0.2.5
type YAMLFSCommandLoader struct {
// contains filtered or unexported fields
}
func NewYAMLFSCommandLoader ¶ added in v0.2.5
func NewYAMLFSCommandLoader( loader YAMLCommandLoader, sourceName string, cmdRoot string, ) *YAMLFSCommandLoader
func (*YAMLFSCommandLoader) LoadCommandsFromFS ¶ added in v0.2.5
func (l *YAMLFSCommandLoader) LoadCommandsFromFS( f fs.FS, dir string, options ...CommandDescriptionOption, ) ([]Command, []*CommandAlias, error)