Documentation
¶
Overview ¶
Package profile provides command profile functionality for executing commands with optional source filtering using CEL expressions.
Profiles define how to execute commands against sets of files, with support for hooks (pre/post execution commands) and source filtering to determine which files should be processed.
Index ¶
- Variables
- type ExecResult
- type HookCommand
- type HookOpts
- type Hooks
- type Plugin
- type PluginOpt
- type Profile
- func (p *Profile) CompileSource() error
- func (p *Profile) Exec(ctx context.Context, dir string) ExecResult
- func (p *Profile) GetPlugin(name string) *Plugin
- func (p *Profile) GetPluginKeyBinds() []*keys.KeyBind
- func (p *Profile) GetPluginNameByKey(keyCode string) string
- func (p *Profile) MatchFiles(dirPath string, files []string) (bool, []string)
- type ProfileOpt
- type UIConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoCommandForPath is returned when no command is found for a path. ErrNoCommandForPath = errors.New("no command for path") // ErrCommandExecution is returned when command execution fails. ErrCommandExecution = errors.New("command execution") // ErrEmptyCommand is returned when a command is empty. ErrEmptyCommand = errors.New("empty command") // ErrHookExecution is returned when hook execution fails. ErrHookExecution = errors.New("hook execution") )
Functions ¶
This section is empty.
Types ¶
type ExecResult ¶
ExecResult represents the result of executing a profile.
type HookCommand ¶
type HookCommand struct {
Command string `validate:"required,alphanum" yaml:"command"`
Args []string `yaml:"args,flow"`
}
HookCommand represents a single hook command to execute.
func NewHookCommand ¶
func NewHookCommand(command string, args ...string) *HookCommand
NewHookCommand creates a new hook command with the given command and arguments.
type HookOpts ¶
type HookOpts func(*Hooks)
HookOpts is a functional option for configuring Hooks.
func WithPostRender ¶
func WithPostRender(hooks ...*HookCommand) HookOpts
WithPostRender adds post-render hooks.
func WithPreRender ¶
func WithPreRender(hooks ...*HookCommand) HookOpts
WithPreRender adds pre-render hooks.
type Hooks ¶
type Hooks struct {
Init []*HookCommand `yaml:"init,omitempty"`
PreRender []*HookCommand `yaml:"preRender,omitempty"`
PostRender []*HookCommand `yaml:"postRender,omitempty"`
}
Hooks represents the different types of hooks that can be executed.
type Plugin ¶
type Plugin struct {
Description string `yaml:"description"`
Keys []keys.Key `yaml:"keys,omitempty"`
Command string `validate:"required,alphanum" yaml:"command"`
Args []string `yaml:"args,flow"`
}
Plugin represents a command plugin that can be executed on demand with keybinds.
type PluginOpt ¶
type PluginOpt func(*Plugin)
PluginOpt is a functional option for configuring a Plugin.
func WithPluginArgs ¶
WithPluginArgs sets the command arguments for the plugin.
func WithPluginKeys ¶
WithPluginKeys sets the keybinds for the plugin.
type Profile ¶
type Profile struct {
Hooks *Hooks `yaml:"hooks,omitempty"`
UI *UIConfig `yaml:"ui,omitempty"` // UI configuration for the profile.
Plugins map[string]*Plugin `yaml:"plugins,omitempty"`
Source string `yaml:"source,omitempty"`
Command string `validate:"required,alphanum" yaml:"command"`
Args []string `yaml:"args,flow"`
// contains filtered or unexported fields
}
Profile represents a command profile with optional source filtering.
The Source field contains a CEL expression that determines which files should be processed by this profile. The expression has access to:
- `files` (list<string>): All file paths in directory
- `dir` (string): The directory path being processed
Source CEL expressions must return a list of files:
- `files.filter(f, pathExt(f) in [".yaml", ".yml"])` - returns all YAML files
- `files.filter(f, pathBase(f) in ["Chart.yaml", "values.yaml"])` - returns Chart and values files
- `files.filter(f, pathBase(f) == "Chart.yaml")` - returns files named Chart.yaml
- `files.filter(f, !pathBase(f).matches(".*test.*")) - returns non-test files
- `files.filter(f, pathBase(f) == "Chart.yaml" && yamlPath(f, "$.apiVersion") == "v2")` - returns charts with apiVersion v2
- `files` - unfiltered list means all files should be processed
- `[]` - empty list means no files should be processed
If no Source expression is provided, the profile will use default file filtering.
func MustNew ¶
func MustNew(command string, opts ...ProfileOpt) *Profile
MustNew creates a new profile and panics if there's an error.
func New ¶
func New(command string, opts ...ProfileOpt) (*Profile, error)
New creates a new profile with the given command and options.
func (*Profile) CompileSource ¶
CompileSource compiles the profile's source expression into a CEL program.
func (*Profile) Exec ¶
func (p *Profile) Exec(ctx context.Context, dir string) ExecResult
Exec runs the profile in the specified directory. Returns ExecResult with the command output and any post-render hooks.
func (*Profile) GetPluginKeyBinds ¶
func (*Profile) GetPluginNameByKey ¶
GetPluginNameByKey returns the name of the first plugin that matches the given key code.
func (*Profile) MatchFiles ¶
MatchFiles checks if the profile's source expression matches files in a directory. The CEL expression must return a list of strings representing files. An empty list means no files should be processed with this profile.
Returns (matches, files) where: - matches: true if the profile should be used (non-empty file list) - files: specific files that were matched.
type ProfileOpt ¶
type ProfileOpt func(*Profile)
ProfileOpt is a functional option for configuring a Profile.
func WithArgs ¶
func WithArgs(args ...string) ProfileOpt
WithArgs sets the command arguments for the profile.
func WithPlugins ¶
func WithPlugins(plugins map[string]*Plugin) ProfileOpt
WithPlugins sets the plugins for the profile.
func WithSource ¶
func WithSource(source string) ProfileOpt
WithSource sets the source filtering expression for the profile.