MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / extractCommandBlock

Function extractCommandBlock

internal/cmdhelp/md_test.go:356–369  ·  view source on GitHub ↗

extractCommandBlock returns the substring of `md` covering one command's section, identified by its full path (e.g. "item create"). Used to scope assertions to a single command rather than the whole document.

(md, path string)

Source from the content-addressed store, hash-verified

354// Used to scope assertions to a single command rather than the whole
355// document.
356func extractCommandBlock(md, path string) string {
357 heading := "## `padtest " + path + "`"
358 idx := strings.Index(md, heading)
359 if idx < 0 {
360 return ""
361 }
362 rest := md[idx+len(heading):]
363 // Block ends at the next `## ` heading at the same level.
364 next := regexp.MustCompile(`(?m)^## `)
365 if loc := next.FindStringIndex(rest); loc != nil {
366 return md[idx : idx+len(heading)+loc[0]]
367 }
368 return md[idx:]
369}
370
371func head(s string, lines int) string {
372 parts := strings.SplitN(s, "\n", lines+1)

Calls

no outgoing calls

Tested by

no test coverage detected