MCPcopy Index your code
hub / github.com/cheat/cheat / New

Function New

internal/sheet/sheet.go:29–65  ·  view source on GitHub ↗

New initializes a new Sheet

(
	title string,
	cheatpath string,
	path string,
	tags []string,
	readOnly bool,
)

Source from the content-addressed store, hash-verified

27
28// New initializes a new Sheet
29func New(
30 title string,
31 cheatpath string,
32 path string,
33 tags []string,
34 readOnly bool,
35) (Sheet, error) {
36
37 // read the cheatsheet file
38 markdown, err := os.ReadFile(path)
39 if err != nil {
40 return Sheet{}, fmt.Errorf("failed to read file: %s, %v", path, err)
41 }
42
43 // parse the raw cheatsheet text
44 fm, text, err := parse(string(markdown))
45 if err != nil {
46 return Sheet{}, fmt.Errorf("failed to parse front-matter: %v", err)
47 }
48
49 // merge the sheet-specific tags into the cheatpath tags
50 tags = append(tags, fm.Tags...)
51
52 // sort strings so they pretty-print nicely
53 sort.Strings(tags)
54
55 // initialize and return a sheet
56 return Sheet{
57 Title: title,
58 CheatPath: cheatpath,
59 Path: path,
60 Text: text,
61 Tags: tags,
62 Syntax: fm.Syntax,
63 ReadOnly: readOnly,
64 }, nil
65}

Callers 6

LoadFunction · 0.92
TestSheetSuccessFunction · 0.70
TestSheetFailureFunction · 0.70
TestCopyFlatFunction · 0.70
TestCopyDeepFunction · 0.70

Calls 1

parseFunction · 0.85

Tested by 5

TestSheetSuccessFunction · 0.56
TestSheetFailureFunction · 0.56
TestCopyFlatFunction · 0.56
TestCopyDeepFunction · 0.56