fs

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadCommandsFromInputs

func LoadCommandsFromInputs(
	commandLoader loaders.YAMLCommandLoader,
	inputs []string,
) ([]cmds.Command, error)

Types

type RemoveCallback

type RemoveCallback func(cmd cmds.Command) error

type Repository

type Repository struct {
	// The root of the repository.
	Root        *TrieNode
	Directories []string
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(options ...RepositoryOption) *Repository

NewRepository creates a new repository.

func (*Repository) Add

func (r *Repository) Add(commands ...cmds.Command)

func (*Repository) CollectCommands

func (r *Repository) CollectCommands(prefix []string, recurse bool) []cmds.Command

func (*Repository) LoadCommands

func (r *Repository) LoadCommands() error

LoadCommands initializes the repository by loading all commands from the loader, if available.

func (*Repository) Remove

func (r *Repository) Remove(prefixes ...[]string)

func (*Repository) Watch

func (r *Repository) Watch(
	ctx context.Context,
	options ...watcher.Option,
) error

type RepositoryOption

type RepositoryOption func(*Repository)

func WithCommandDescriptionOptions

func WithCommandDescriptionOptions(cmdOptions []cmds.CommandDescriptionOption) RepositoryOption

func WithCommandLoader

func WithCommandLoader(loader loaders.ReaderCommandLoader) RepositoryOption

WithCommandLoader sets the command loader to use when loading commands from an updated file when it changes.

func WithCommands

func WithCommands(commands ...cmds.Command) RepositoryOption

func WithDirectories

func WithDirectories(directories []string) RepositoryOption

func WithDirectory

func WithDirectory(directory string) RepositoryOption

func WithFSLoader

func WithFSLoader(loader loaders.FSCommandLoader) RepositoryOption

WithFSLoader sets the command loader to use when loading commands from the filesystem on startup or when a directory changes.

func WithRemoveCallback

func WithRemoveCallback(callback RemoveCallback) RepositoryOption

func WithUpdateCallback

func WithUpdateCallback(callback UpdateCallback) RepositoryOption

type TrieNode

type TrieNode struct {
	Children map[string]*TrieNode
	Commands []cmds.Command
}

func NewTrieNode

func NewTrieNode(commands []cmds.Command, aliases []*alias.CommandAlias) *TrieNode

NewTrieNode creates a new trie node.

func (*TrieNode) CollectCommands

func (t *TrieNode) CollectCommands(prefix []string, recurse bool) []cmds.Command

CollectCommands collects all commands and aliases under the given prefix.

func (*TrieNode) FindCommand

func (t *TrieNode) FindCommand(path []string) (cmds.Command, bool)

func (*TrieNode) InsertCommand

func (t *TrieNode) InsertCommand(prefix []string, command cmds.Command)

InsertCommand inserts a command in the trie, replacing it if it already exists.

func (*TrieNode) Remove

func (t *TrieNode) Remove(prefix []string) []cmds.Command

Remove removes a command from the trie.

type UpdateCallback

type UpdateCallback func(cmd cmds.Command) error

Jump to

Keyboard shortcuts

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