MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / makeSection

Method makeSection

init/config/config.go:35–89  ·  view source on GitHub ↗

Not all sections have defs, and it may be nil. Defs only work on 'list' sections.

(name section, showHeader, showValue bool)

Source from the content-addressed store, hash-verified

33
34// Not all sections have defs, and it may be nil. Defs only work on 'list' sections.
35func (h *Header) makeSection(name section, showHeader, showValue bool) string {
36 var buf bytes.Buffer
37
38 // Print section header text.
39 if h.Text != "" {
40 buf.WriteString(h.Text)
41 }
42
43 space, comment := "", "#"
44 if showHeader {
45 // this only happens when a defined section has a comment override on the repeating headers.
46 comment = ""
47 }
48
49 if !h.NoHeader { // Print the [section] or [[section]] header.
50 space = " "
51
52 if h.Kind == list { // list sections are commented by default.
53 buf.WriteString(comment + "[[" + string(name) + "]]" + "\n") // list sections use double-brackets.
54 } else {
55 buf.WriteString("[" + string(name) + "]" + "\n") // non-list sections use single brackets.
56 }
57 }
58
59 for _, param := range h.Params {
60 // Print an empty newline for each param if the section has no header and the param has a description.
61 if h.NoHeader && param.Desc != "" {
62 buf.WriteString("\n")
63 }
64
65 // Add ## to the beginning of each line in the description.
66 // Uses the newline \n character to figure out where each line begins.
67 if param.Desc != "" {
68 buf.WriteString("## " + strings.ReplaceAll(strings.TrimSpace(param.Desc), "\n", "\n## ") + "\n")
69 }
70
71 switch {
72 default:
73 fallthrough
74 case showValue:
75 buf.WriteString(fmt.Sprintf("%s%s = %s\n", space, param.Name, param.Value()))
76 case param.Example != nil:
77 // If example is not empty, use that commented out, otherwise use the default.
78 fallthrough
79 case h.Kind == list:
80 // If the 'kind' is a 'list', we comment all the parameters.
81 buf.WriteString(fmt.Sprintf("#%s%s = %s\n", space, param.Name, param.Value()))
82 }
83 }
84
85 // Each section needs a newline at the end.
86 buf.WriteString("\n")
87
88 return buf.String()
89}
90
91func (p *Param) Value() string {
92 // If example is not empty, use that commented out, otherwise use the default.

Callers 3

makeDocsMethod · 0.95
createConfFileFunction · 0.80
makeDefinedSectionMethod · 0.80

Calls 2

ValueMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected