cmds

package
v0.2.45 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2023 License: MIT Imports: 15 Imported by: 48

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetParentsFromDir added in v0.2.27

func GetParentsFromDir(dir string, cmdRoot string) []string

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 {
	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 WithFlags added in v0.2.10

func WithLayers added in v0.2.10

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 GlazeCommand added in v0.2.45

type GlazeCommand interface {
	Command
	// 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 GlazeCommand specific layer,
	// which would allow the GlazeCommand 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.
	//
	// https://github.com/go-go-golems/glazed/issues/217
	// https://github.com/go-go-golems/glazed/issues/216
	// See https://github.com/go-go-golems/glazed/issues/173
	Run(
		ctx context.Context,
		parsedLayers map[string]*layers.ParsedParameterLayer,
		ps map[string]interface{},
		gp Processor,
	) error
}

type GlazeProcessor added in v0.2.6

type GlazeProcessor struct {
	// contains filtered or unexported fields
}

func NewGlazeProcessor added in v0.2.6

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
}

YAMLFSCommandLoader walks a FS and finds all yaml files, loading them using the passed YAMLCommandLoader.

It handles the following generic functionality: - recursive FS walking - setting SourceName for each command - setting Parents for each command

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)

LoadCommandsFromFS walks the FS and loads all commands and command aliases found.

TODO(manuel, 2023-03-16) Add loading of helpsystem files See https://github.com/go-go-golems/glazed/issues/55 See https://github.com/go-go-golems/glazed/issues/218

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL