Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .claude/CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ Use conventional commit format (feat:, fix:, chore:, etc.) for commit titles.
5. Run `slack docgen ./docs/reference` to generate docs
6. Consider adding command alias in `AliasMap` if appropriate

### Command Descriptions and Documentation

Command `Long` descriptions are parsed as Go `text/template` by `docgen` and rendered as MDX for the documentation site. Escape `{` and `[` as `\{` and `\[` in description text to prevent build errors on the docs site. Available template functions: `{{Emoji "name"}}`, `{{LinkText "url"}}`, `{{ToBold "text"}}`.

### Adding New Dependencies

1. Update `go.mod` with the new module version
Expand Down
27 changes: 27 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"os"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -290,3 +291,29 @@ func testExecCmd(ctx context.Context, args []string) (string, error) {
}
return clientsMock.GetCombinedOutput(), nil
}

func Test_CommandDescriptionsRenderForDocs(t *testing.T) {
ctx := slackcontext.MockContext(t.Context())
tmp, _ := os.MkdirTemp("", "")
_ = os.Chdir(tmp)
defer os.RemoveAll(tmp)

cmd, _ := Init(ctx)

// Matches a lone { that is not escaped (\{) and not part of a Go template ({{)
unescapedBrace := regexp.MustCompile(`[^\\{]\{[^{]`)

var walk func(*cobra.Command)
walk = func(c *cobra.Command) {
if c.Long != "" {
t.Run(c.CommandPath(), func(t *testing.T) {
assert.NotRegexp(t, unescapedBrace, c.Long,
"description contains unescaped '{' which breaks the MDX docs site; escape as \\{")
})
}
for _, child := range c.Commands() {
walk(child)
}
}
walk(cmd)
}
Loading