MCPcopy
hub / github.com/cheat/cheat / ExpandTemplate

Function ExpandTemplate

internal/installer/template.go:22–39  ·  view source on GitHub ↗

ExpandTemplate replaces placeholder tokens in the config template with platform-appropriate paths derived from confpath.

(configs string, confpath string)

Source from the content-addressed store, hash-verified

20// ExpandTemplate replaces placeholder tokens in the config template with
21// platform-appropriate paths derived from confpath.
22func ExpandTemplate(configs string, confpath string) string {
23 community, personal, work := cheatsheetDirs(confpath)
24
25 // substitute paths
26 configs = strings.ReplaceAll(configs, "COMMUNITY_PATH", community)
27 configs = strings.ReplaceAll(configs, "PERSONAL_PATH", personal)
28 configs = strings.ReplaceAll(configs, "WORK_PATH", work)
29
30 // locate and set a default pager
31 configs = strings.ReplaceAll(configs, "PAGER_PATH", config.Pager())
32
33 // locate and set a default editor
34 if editor, err := config.Editor(); err == nil {
35 configs = strings.ReplaceAll(configs, "EDITOR_PATH", editor)
36 }
37
38 return configs
39}
40
41// CommentCommunity comments out the community cheatpath block in the config
42// template. This is used when the community cheatsheets directory won't exist

Callers 2

cmdInitFunction · 0.92
RunFunction · 0.85

Calls 3

PagerFunction · 0.92
EditorFunction · 0.92
cheatsheetDirsFunction · 0.85

Tested by

no test coverage detected