-
Notifications
You must be signed in to change notification settings - Fork 4
/
type.go
72 lines (62 loc) · 2.46 KB
/
type.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
package action
import (
"projectforge.dev/projectforge/app/util"
)
type Type struct {
Key string
Title string
Icon string
Description string
Hidden bool
}
var (
TypeAudit = Type{Key: "audit", Title: "Audit", Icon: "scale", Description: "Audits the project files, detecting invalid files and empty folders"}
TypeBuild = Type{Key: "build", Title: "Build", Icon: "hammer", Description: "Builds the project, many options available"}
TypeCreate = Type{Key: "create", Title: "Create", Icon: "folder-plus", Description: "Creates a new project"}
TypeDebug = Type{Key: "debug", Title: "Debug", Icon: "bug", Description: "Dumps information about the project"}
TypeDoctor = Type{Key: "doctor", Title: "Doctor", Icon: "first-aid", Description: "Makes sure your machine has the required dependencies"}
TypeGenerate = Type{Key: "generate", Title: "Generate", Icon: "forward", Description: "Applies pending changes to files as required"}
TypePreview = Type{Key: "preview", Title: "Preview", Icon: "play", Description: "Show what would happen if you generate"}
TypeRules = Type{Key: "rules", Title: "Rules", Icon: "play", Description: "Apply export rules from json file located at ./rules.json"}
TypeSVG = Type{Key: "svg", Title: "SVG", Icon: "icons", Description: "Builds the project's SVG files"}
TypeTest = Type{Key: "test", Title: "Test", Icon: "wrench", Description: "Runs internal tests, you probably don't want this", Hidden: true}
)
var (
AllTypes = []Type{TypeAudit, TypeBuild, TypeCreate, TypeDebug, TypeDoctor, TypeGenerate, TypePreview, TypeRules, TypeSVG, TypeTest}
ProjectTypes = []Type{TypePreview, TypeGenerate, TypeAudit, TypeBuild}
)
func TypeFromString(s string) Type {
for _, t := range AllTypes {
if t.Key == s {
return t
}
}
return Type{Key: s, Title: "Error", Icon: "star", Description: "No action type available with key [" + s + "]"}
}
func (t *Type) String() string {
return t.Key
}
func (t *Type) Matches(x Type) bool {
return t.Key == x.Key
}
func (t *Type) MarshalJSON() ([]byte, error) {
return util.ToJSONBytes(t.Key, false), nil
}
func (t *Type) UnmarshalJSON(data []byte) error {
var s string
if err := util.FromJSON(data, &s); err != nil {
return err
}
x := TypeFromString(s)
*t = x
return nil
}
func (t *Type) Expensive(cfg util.ValueMap) bool {
if t.Matches(TypeBuild) {
switch cfg.GetStringOpt("phase") {
case buildDeps.Key, buildLint.Key, buildFull.Key:
return true
}
}
return false
}