loaders

package
v0.5.34 Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2025 License: MIT Imports: 12 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FileNameToFsFilePath added in v0.4.35

func FileNameToFsFilePath(fileName string) (fs.FS, string, error)

func GetParentsFromDir

func GetParentsFromDir(dir 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.

func LoadCommandAliasFromYAML

func LoadCommandAliasFromYAML(s io.Reader, options ...alias.Option) ([]*alias.CommandAlias, error)

func LoadCommandOrAliasFromReader added in v0.4.34

func LoadCommandOrAliasFromReader(
	r io.Reader,
	rawLoadCommand LoadReaderCommandFunc,
	options []cmds.CommandDescriptionOption,
	aliasOptions []alias.Option,
) ([]cmds.Command, error)

func LoadCommandsFromFS added in v0.4.35

func LoadCommandsFromFS(
	f fs.FS,
	dir string,
	source string,
	loader CommandLoader,
	options []cmds.CommandDescriptionOption,
	aliasOptions []alias.Option,
) ([]cmds.Command, 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

Types

type BaseCommand added in v0.5.30

type BaseCommand struct {
	Type string `yaml:"type" json:"type"`
}

BaseCommand represents the minimal structure needed to determine the type of a command

type CommandLoader added in v0.4.35

type CommandLoader interface {
	LoadCommands(
		f fs.FS, entryName string,
		options []cmds.CommandDescriptionOption,
		aliasOptions []alias.Option,
	) ([]cmds.Command, error)
	IsFileSupported(f fs.FS, fileName string) bool
}

CommandLoader 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 LoadReaderCommandFunc added in v0.4.34

type LoadReaderCommandFunc func(
	r io.Reader,
	options []cmds.CommandDescriptionOption,
	aliasOptions []alias.Option,
) ([]cmds.Command, error)

type MultiLoader added in v0.5.30

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

MultiLoader implements CommandLoader and dispatches to registered loaders based on the Type field

func NewMultiLoader added in v0.5.30

func NewMultiLoader() *MultiLoader

NewMultiLoader creates a new MultiLoader instance

func (*MultiLoader) IsFileSupported added in v0.5.30

func (m *MultiLoader) IsFileSupported(f fs.FS, fileName string) bool

IsFileSupported implements the CommandLoader interface

func (*MultiLoader) LoadCommands added in v0.5.30

func (m *MultiLoader) LoadCommands(
	f fs.FS,
	entryName string,
	options []cmds.CommandDescriptionOption,
	aliasOptions []alias.Option,
) ([]cmds.Command, error)

LoadCommands implements the CommandLoader interface

func (*MultiLoader) RegisterLoader added in v0.5.30

func (m *MultiLoader) RegisterLoader(typeName string, loader CommandLoader)

RegisterLoader registers a new loader for a specific type

func (*MultiLoader) SetDefaultLoader added in v0.5.30

func (m *MultiLoader) SetDefaultLoader(loader CommandLoader)

SetDefaultLoader sets the default loader to use when no Type field is present

Jump to

Keyboard shortcuts

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