command

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package command discovers, parses, and expands custom slash commands.

Command definitions are loaded from (in priority order):

  1. Project-level MD: .chord/commands/**/*.md
  2. Global-level MD: <config-home>/commands/**/*.md
  3. Project-level YAML: .chord/config.yaml commands field
  4. Global-level YAML: <config-home>/config.yaml commands field

First occurrence of a name wins. Built-in names are always reserved.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Expand

func Expand(template, args string) string

Expand applies the $ARGUMENTS substitution rule to a template. If template contains $ARGUMENTS, all occurrences are replaced with args. If template does not contain $ARGUMENTS and args is non-empty, args is appended after two newlines. If args is empty and template has no $ARGUMENTS, template is returned as-is.

func ParseInput

func ParseInput(trimmedLine string) (name, args string)

ParseInput splits a trimmed slash line into (commandName, arguments). commandName is without the leading "/", e.g. "review". arguments is everything after the first whitespace-separated token. Returns ("", "") if input does not start with "/".

Types

type Definition

type Definition struct {
	Name        string // without leading "/", e.g. "review" or "foo/bar"
	Description string // from frontmatter; may be empty
	Template    string // full body (with $ARGUMENTS placeholder if present)
	Location    string // absolute path; YAML commands use config file path
	Source      string // project-md / global-md / project-yaml / global-yaml
}

Definition holds a single custom slash command.

func Load

func Load(opts LoadOptions) ([]*Definition, []string)

Load scans all four layers, merges them, and returns the final definitions. Warnings from bad files or reserved names are returned but do not block loading.

func Merge

func Merge(sources ...[]*Definition) ([]*Definition, []string)

Merge combines definitions from multiple sources in priority order. Built-in names are skipped with a warning. First occurrence of a name wins.

type LoadOptions

type LoadOptions struct {
	ProjectRoot    string            // project working directory
	ConfigHome     string            // user-level config directory
	ProjectCfg     map[string]string // project config.yaml commands
	ProjectCfgPath string            // absolute path to project config.yaml
	GlobalCfg      map[string]string // global config.yaml commands
	GlobalCfgPath  string            // absolute path to global config.yaml
}

LoadOptions holds the paths needed to load commands from all four layers.

Jump to

Keyboard shortcuts

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