-
Notifications
You must be signed in to change notification settings - Fork 6
/
core_doc.go
80 lines (73 loc) · 1.65 KB
/
core_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package object
import (
"fmt"
"sort"
"github.com/opensvc/om3/core/driver"
"github.com/opensvc/om3/core/keywords"
"github.com/opensvc/om3/core/resource"
"github.com/opensvc/om3/util/key"
)
func drvDoc(drvID driver.ID, kwName string) (string, error) {
factory := resource.NewResourceFunc(drvID)
if factory == nil {
return "", fmt.Errorf("driver not found")
}
r := factory()
buff := ""
store := keywords.Store(r.Manifest().Keywords())
sort.Sort(store)
for _, kw := range store {
if (kwName != "") && kw.Option != kwName {
continue
}
buff += kw.Doc()
buff += "\n"
}
return buff, nil
}
func (t *core) defaultDoc() (string, error) {
buff := ""
sort.Sort(keywordStore)
for _, kw := range keywordStore {
if kw.Section != "DEFAULT" {
continue
}
if !kw.Kind.Has(t.path.Kind) {
continue
}
buff += kw.Doc()
buff += "\n"
}
return buff, nil
}
func (t *core) Doc(drvStr, kwStr string) (string, error) {
switch {
case drvStr == "":
return t.KeywordDoc(kwStr)
case kwStr == "":
return t.DriverDoc(drvStr)
default:
drvID := driver.Parse(drvStr)
return drvDoc(drvID, kwStr)
}
}
// KeywordDoc returns the documentation of a single keyword.
func (t *core) KeywordDoc(s string) (string, error) {
k := key.Parse(s)
switch {
case k.Option != "":
return t.config.Doc(k)
case k.Section == "DEFAULT":
return t.defaultDoc()
case k.Section != "":
drvID, _ := driverIDFromRID(t, k.Section)
return drvDoc(drvID, "")
default:
return "", nil
}
}
// DriverDoc returns the documentation of all keywords of the specified driver.
func (t *core) DriverDoc(s string) (string, error) {
drvID := driver.Parse(s)
return drvDoc(drvID, "")
}