Documentation
¶
Overview ¶
Package actions handles staghorn action parsing, registry, and rendering.
Index ¶
- func NewActionTemplate(name, description string) string
- func ParseArgs(rawArgs []string) (map[string]string, error)
- type Action
- func (a *Action) ExtractVariables() []string
- func (a *Action) FormatArgsHelp() string
- func (a *Action) GetArg(name string) *Arg
- func (a *Action) GetArgWithDefault(args map[string]string, name string) string
- func (a *Action) HasArg(name string) bool
- func (a *Action) Render(args map[string]string) (string, error)
- func (a *Action) RenderWithValidation(args map[string]string) (string, []string, error)
- func (a *Action) ValidateArgs(args map[string]string) error
- type Arg
- type Frontmatter
- type Registry
- func (r *Registry) Add(action *Action)
- func (r *Registry) AddAll(actions []*Action)
- func (r *Registry) All() []*Action
- func (r *Registry) BySource(source Source) []*Action
- func (r *Registry) ByTag(tag string) []*Action
- func (r *Registry) Count() int
- func (r *Registry) CountBySource() map[Source]int
- func (r *Registry) Get(name string) *Action
- func (r *Registry) GetAllVersions(name string) []*Action
- func (r *Registry) IsOverridden(name string, source Source) bool
- func (r *Registry) Names() []string
- type Source
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewActionTemplate ¶
NewActionTemplate returns a template for creating a new action.
Types ¶
type Action ¶
type Action struct {
Frontmatter
Body string // Markdown content after frontmatter
Source Source // Where this action came from
FilePath string // Path to the action file
}
Action represents a staghorn action.
func LoadFromDirectory ¶
LoadFromDirectory loads all actions from a directory.
func (*Action) ExtractVariables ¶
ExtractVariables returns all variable names used in the action body.
func (*Action) FormatArgsHelp ¶
FormatArgsHelp formats the arguments help text for an action.
func (*Action) GetArgWithDefault ¶
GetArgWithDefault returns the argument value or its default.
func (*Action) Render ¶
Render renders an action's body with the provided arguments. Uses a simple {{varname}} syntax for user-friendliness.
func (*Action) RenderWithValidation ¶
RenderWithValidation renders and also returns warnings for undefined variables.
type Arg ¶
type Arg struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Default string `yaml:"default"`
Options []string `yaml:"options,omitempty"` // Valid options if constrained
Required bool `yaml:"required"`
}
Arg defines an action argument.
type Frontmatter ¶
type Frontmatter struct {
Name string `yaml:"name"`
Description string `yaml:"description"`
Tags []string `yaml:"tags,omitempty"`
Args []Arg `yaml:"args,omitempty"`
}
Frontmatter contains the YAML frontmatter of an action.
func ReadFrontmatterOnly ¶
func ReadFrontmatterOnly(path string) (*Frontmatter, error)
ReadFrontmatterOnly reads just the frontmatter without loading the full body. Useful for listing actions without loading all content into memory.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages actions from multiple sources with precedence handling. Precedence (highest to lowest): project > personal > team
func LoadRegistry ¶
LoadRegistry creates a registry by loading actions from all sources.
func (*Registry) Add ¶
Add adds an action to the registry. If an action with the same name exists from a lower precedence source, it's overridden.
func (*Registry) CountBySource ¶
CountBySource returns counts per source.
func (*Registry) GetAllVersions ¶
GetAllVersions returns all versions of an action across sources.
func (*Registry) IsOverridden ¶
IsOverridden checks if an action from a lower source is overridden.