MCPcopy Index your code
hub / github.com/cli/cli / Parse

Function Parse

internal/skills/frontmatter/frontmatter.go:31–63  ·  view source on GitHub ↗

Parse extracts YAML frontmatter from a SKILL.md file. Frontmatter is delimited by --- on its own lines.

(content string)

Source from the content-addressed store, hash-verified

29// Parse extracts YAML frontmatter from a SKILL.md file.
30// Frontmatter is delimited by --- on its own lines.
31func Parse(content string) (*ParseResult, error) {
32 trimmed := strings.TrimLeft(content, "\r\n")
33 if !strings.HasPrefix(trimmed, delimiter) {
34 return &ParseResult{Body: content}, nil
35 }
36
37 rest := trimmed[len(delimiter):]
38 rest = strings.TrimLeft(rest, "\r\n")
39 endIdx := strings.Index(rest, "\n"+delimiter)
40 if endIdx == -1 {
41 return &ParseResult{Body: content}, nil
42 }
43
44 yamlContent := rest[:endIdx]
45 body := rest[endIdx+len("\n"+delimiter):]
46 body = strings.TrimLeft(body, "\r\n")
47
48 var rawYAML map[string]interface{}
49 if err := yaml.Unmarshal([]byte(yamlContent), &rawYAML); err != nil {
50 return nil, fmt.Errorf("invalid frontmatter YAML: %w", err)
51 }
52
53 var meta Metadata
54 if err := yaml.Unmarshal([]byte(yamlContent), &meta); err != nil {
55 return nil, fmt.Errorf("invalid frontmatter YAML: %w", err)
56 }
57
58 return &ParseResult{
59 Metadata: meta,
60 Body: body,
61 RawYAML: rawYAML,
62 }, nil
63}
64
65// InjectGitHubMetadata adds GitHub tracking metadata to the spec-defined
66// "metadata" map in frontmatter. Keys are prefixed with "github-" to avoid

Callers 13

fetchDescriptionsFunction · 0.92
parseInstalledSkillFunction · 0.92
parseInstalledSkillFunction · 0.92
existingSkillPromptFunction · 0.92
checkUpstreamProvenanceFunction · 0.92
renderMarkdownPreviewFunction · 0.92
publishRunFunction · 0.92
stripGitHubMetadataFunction · 0.92
fetchDescriptionFunction · 0.92
localSkillFromDirFunction · 0.92
InjectGitHubMetadataFunction · 0.85
InjectLocalMetadataFunction · 0.85

Calls 1

ErrorfMethod · 0.65

Tested by 1

TestParseFunction · 0.68