Documentation ¶
Index ¶
- 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 WithParents(p ...string) CommandDescriptionOption
- func WithShort(s string) CommandDescriptionOption
- func WithSource(s string) CommandDescriptionOption
- type ExitWithoutGlazeError
- type FSCommandLoader
- type GlazeProcessor
- type YAMLCommandLoader
- type YAMLFSCommandLoader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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 *GlazeProcessor, ) 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 *GlazeProcessor, ) 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
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 WithParents ¶ added in v0.2.10
func WithParents(p ...string) 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
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) ([]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 YAMLCommandLoader ¶ added in v0.2.5
type YAMLCommandLoader interface { LoadCommandFromYAML(s io.Reader) ([]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) ([]Command, []*CommandAlias, error)