MCPcopy Create free account
hub / github.com/cli/cli / Parse

Function Parse

internal/skills/frontmatter/frontmatter.go:32–64  ·  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

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