MCPcopy
hub / github.com/cli/cli / ExtractName

Function ExtractName

pkg/githubtemplate/github_template.go:87–99  ·  view source on GitHub ↗

ExtractName returns the name of the template from YAML front-matter

(filePath string)

Source from the content-addressed store, hash-verified

85
86// ExtractName returns the name of the template from YAML front-matter
87func ExtractName(filePath string) string {
88 contents, err := os.ReadFile(filePath)
89 frontmatterBoundaries := detectFrontmatter(contents)
90 if err == nil && frontmatterBoundaries[0] == 0 {
91 templateData := struct {
92 Name string
93 }{}
94 if err := yaml.Unmarshal(contents[0:frontmatterBoundaries[1]], &templateData); err == nil && templateData.Name != "" {
95 return templateData.Name
96 }
97 }
98 return path.Base(filePath)
99}
100
101// ExtractTitle returns the title of the template from YAML front-matter
102func ExtractTitle(filePath string) string {

Callers 2

NameMethod · 0.92
TestExtractNameFunction · 0.85

Calls 2

detectFrontmatterFunction · 0.85
BaseMethod · 0.80

Tested by 1

TestExtractNameFunction · 0.68