Documentation
¶
Overview ¶
Package commands handles staghorn command parsing, registry, and rendering.
Index ¶
- func ConvertToClaude(cmd *Command) string
- func NewCommandTemplate(name, description string) string
- func ParseArgs(rawArgs []string) (map[string]string, error)
- type Arg
- type ClaudeCommand
- type Command
- func (c *Command) ExtractVariables() []string
- func (c *Command) FormatArgsHelp() string
- func (c *Command) GetArg(name string) *Arg
- func (c *Command) GetArgWithDefault(args map[string]string, name string) string
- func (c *Command) HasArg(name string) bool
- func (c *Command) Render(args map[string]string) (string, error)
- func (c *Command) RenderWithValidation(args map[string]string) (string, []string, error)
- func (c *Command) ValidateArgs(args map[string]string) error
- type Frontmatter
- type Registry
- func (r *Registry) Add(cmd *Command)
- func (r *Registry) AddAll(cmds []*Command)
- func (r *Registry) All() []*Command
- func (r *Registry) BySource(source Source) []*Command
- func (r *Registry) ByTag(tag string) []*Command
- func (r *Registry) Count() int
- func (r *Registry) CountBySource() map[Source]int
- func (r *Registry) Get(name string) *Command
- func (r *Registry) GetAllVersions(name string) []*Command
- 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 ConvertToClaude ¶
ConvertToClaude converts a staghorn command to Claude Code command format. It adds a usage hint so Claude (the LLM) understands the {{varname}} syntax.
func NewCommandTemplate ¶
NewCommandTemplate returns a template for creating a new command.
Types ¶
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 a command argument.
type ClaudeCommand ¶
type ClaudeCommand struct {
Name string `yaml:"name"`
Description string `yaml:"description,omitempty"`
}
ClaudeCommand represents a Claude Code custom command.
type Command ¶
type Command struct {
Frontmatter
Body string // Markdown content after frontmatter
Source Source // Where this command came from
FilePath string // Path to the command file
}
Command represents a staghorn command.
func LoadFromDirectory ¶
LoadFromDirectory loads all commands from a directory.
func (*Command) ExtractVariables ¶
ExtractVariables returns all variable names used in the command body.
func (*Command) FormatArgsHelp ¶
FormatArgsHelp formats the arguments help text for a command.
func (*Command) GetArgWithDefault ¶
GetArgWithDefault returns the argument value or its default.
func (*Command) Render ¶
Render renders a command's body with the provided arguments. Uses a simple {{varname}} syntax for user-friendliness.
func (*Command) RenderWithValidation ¶
RenderWithValidation renders and also returns warnings for undefined variables.
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 a command.
func ReadFrontmatterOnly ¶
func ReadFrontmatterOnly(path string) (*Frontmatter, error)
ReadFrontmatterOnly reads just the frontmatter without loading the full body. Useful for listing commands without loading all content into memory.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages commands from multiple sources with precedence handling. Precedence (highest to lowest): project > personal > team
func LoadRegistry ¶
LoadRegistry creates a registry by loading commands from all sources.
func (*Registry) Add ¶
Add adds a command to the registry. If a command 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 a command across sources.
func (*Registry) IsOverridden ¶
IsOverridden checks if a command from a lower source is overridden.