MCPcopy Index your code
hub / github.com/cortexproject/cortex / writeConfigEntry

Method writeConfigEntry

tools/doc-generator/writer.go:32–77  ·  view source on GitHub ↗
(e *configEntry, indent int)

Source from the content-addressed store, hash-verified

30}
31
32func (w *specWriter) writeConfigEntry(e *configEntry, indent int) {
33 if e.kind == "block" {
34 // If the block is a root block it will have its dedicated section in the doc,
35 // so here we've just to write down the reference without re-iterating on it.
36 if e.root {
37 // Description
38 w.writeComment(e.blockDesc, indent)
39 if e.block.flagsPrefix != "" {
40 w.writeComment(fmt.Sprintf("The CLI flags prefix for this block config is: %s", e.block.flagsPrefix), indent)
41 }
42
43 // Block reference without entries, because it's a root block
44 w.out.WriteString(pad(indent) + "[" + e.name + ": <" + e.block.name + ">]\n")
45 } else {
46 // Description
47 w.writeComment(e.blockDesc, indent)
48
49 // Name
50 w.out.WriteString(pad(indent) + e.name + ":\n")
51
52 // Entries
53 w.writeConfigBlock(e.block, indent+tabWidth)
54 }
55 }
56
57 if e.kind == "field" {
58 // Description
59 w.writeComment(e.fieldDesc, indent)
60 w.writeFlag(e.fieldFlag, indent)
61
62 // Specification
63 fieldDefault := e.fieldDefault
64 switch e.fieldType {
65 case "string":
66 fieldDefault = strconv.Quote(fieldDefault)
67 case "duration":
68 fieldDefault = cleanupDuration(fieldDefault)
69 }
70
71 if e.required {
72 w.out.WriteString(pad(indent) + e.name + ": <" + e.fieldType + "> | default = " + fieldDefault + "\n")
73 } else {
74 w.out.WriteString(pad(indent) + "[" + e.name + ": <" + e.fieldType + "> | default = " + fieldDefault + "]\n")
75 }
76 }
77}
78
79func (w *specWriter) writeFlag(name string, indent int) {
80 if name == "" {

Callers 1

writeConfigBlockMethod · 0.95

Calls 6

writeCommentMethod · 0.95
writeConfigBlockMethod · 0.95
writeFlagMethod · 0.95
padFunction · 0.85
cleanupDurationFunction · 0.85
WriteStringMethod · 0.80

Tested by

no test coverage detected