-
Notifications
You must be signed in to change notification settings - Fork 4
/
help.go
87 lines (83 loc) · 2.3 KB
/
help.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
81
82
83
84
85
86
87
package model
import (
"fmt"
"projectforge.dev/projectforge/app/lib/types"
"projectforge.dev/projectforge/app/project/export/enum"
)
func Help(t types.Type, f string, nullable bool, enums enum.Enums) (string, error) {
q := func(s string) string {
if nullable {
s += " (optional)"
}
return "\"" + s + "\""
}
switch t.Key() {
case types.KeyAny:
return q("Interface, could be anything"), nil
case types.KeyBool:
return q("Value [true] or [false]"), nil
case types.KeyEnum:
e, err := AsEnumInstance(t, enums)
if err != nil {
return "", err
}
return fmt.Sprintf("%s.All%s.Help()", e.Package, e.ProperPlural()), nil
case types.KeyInt:
return q("Integer"), nil
case types.KeyFloat:
return q("Floating-point number"), nil
case types.KeyList:
lt := types.TypeAs[*types.List](t)
if e, _ := AsEnumInstance(lt.V, enums); e != nil {
return fmt.Sprintf("%s.All%s.Help()", e.Package, e.ProperPlural()), nil
}
return q("Comma-separated list of values"), nil
case types.KeyMap, types.KeyValueMap:
return q("JSON object"), nil
case types.KeyReference:
return q("[" + asRefK(t) + "], as a JSON object"), nil
case types.KeyString:
switch f {
case FmtCode.Key, FmtCodeHidden.Key:
return q("Formatted code"), nil
case FmtColor.Key:
return q("RGB color in string form"), nil
case FmtCountry.Key:
return q("Two-digit country code"), nil
case FmtHTML.Key:
return q("HTML code, in string form"), nil
case FmtIcon.Key:
return q("SVG icon key or URL"), nil
case FmtImage.Key:
return q("URL to valid image"), nil
case FmtJSON.Key:
return q("JSON code"), nil
case FmtSeconds.Key:
return q("Number of wall-clock seconds"), nil
case FmtSQL.Key:
return q("SQL code"), nil
case FmtURL.Key:
return q("URL in string form"), nil
default:
return q("String text"), nil
}
case types.KeyDate:
return q("Calendar date"), nil
case types.KeyTimestamp:
return q("Date and time, in almost any format"), nil
case types.KeyUUID:
return q("UUID in format (00000000-0000-0000-0000-000000000000)"), nil
default:
return q(t.Key()), nil
}
}
func (c *Column) Help(enums enum.Enums) (string, error) {
if c.HelpString != "" {
return "\"" + c.HelpString + "\"", nil
}
ret, err := Help(c.Type, c.Format, c.Nullable, enums)
if err != nil {
return "", err
}
return ret, nil
}