-
Notifications
You must be signed in to change notification settings - Fork 6
/
node_doc.go
61 lines (55 loc) · 1.16 KB
/
node_doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package object
import (
"slices"
"sort"
"strings"
"github.com/opensvc/om3/util/key"
)
func nodeDrvDoc(group, name string) (string, error) {
buff := ""
sort.Sort(nodeKeywordStore)
for _, kw := range nodeKeywordStore {
if kw.Section != group {
continue
}
if len(kw.Types) > 0 && !slices.Contains(kw.Types, name) {
continue
}
buff += kw.Doc()
buff += "\n"
}
return buff, nil
}
func nodeSectionDoc(s string) (string, error) {
buff := ""
sort.Sort(nodeKeywordStore)
for _, kw := range nodeKeywordStore {
if kw.Section != s {
continue
}
buff += kw.Doc()
buff += "\n"
}
return buff, nil
}
// KeywordDoc returns the documentation of a single keyword.
func (t *Node) KeywordDoc(s string) (string, error) {
k := key.Parse(s)
switch {
case (k.Option != "") && (k.Option != "*"):
return t.config.Doc(k)
case k.Section != "":
return nodeSectionDoc(k.Section)
default:
return "", nil
}
}
// DriverDoc returns the documentation of all keywords of the specified driver.
func (t *Node) DriverDoc(s string) (string, error) {
l := strings.SplitN(s, ".", 2)
if len(l) == 2 {
return nodeDrvDoc(l[0], l[1])
} else {
return nodeDrvDoc(s, "")
}
}