This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
workflow.go
98 lines (84 loc) · 2.93 KB
/
workflow.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
88
89
90
91
92
93
94
95
96
97
98
package workflow
import (
"fmt"
"github.com/jclem/alpaca/config"
)
// Info represents an info.plist in a workflow.
type Info struct {
BundleID string `plist:"bundleid,omitempty"`
Connections map[string][]Connection `plist:"connections,omitempty"`
CreatedBy string `plist:"createdby,omitempty"`
Description string `plist:"description,omitempty"`
Name string `plist:"name,omitempty"`
Objects []map[string]interface{} `plist:"objects,omitempty"`
Readme string `plist:"readme,omitempty"`
UIData uidata `plist:"uidata,omitempty"`
WebAddress string `plist:"webaddress,omitempty"`
Variables map[string]string `plist:"variables,omitempty"`
VariablesDontExport []string `plist:"variablesdontexport,omitempty"`
Version string `plist:"version,omitempty"`
path string
}
// NewFromConfig creates a new Info struct from an Alpaca config struct.
func NewFromConfig(path string, c config.Config) (*Info, error) {
i := Info{
BundleID: c.BundleID,
Connections: map[string][]Connection{},
CreatedBy: c.Author,
Description: c.Description,
Name: c.Name,
Readme: c.Readme,
WebAddress: c.URL,
Version: c.Version,
Variables: c.Variables,
}
for varName := range i.Variables {
i.VariablesDontExport = append(i.VariablesDontExport, varName)
}
// Build workflow connections.
for _, cfgObj := range c.Objects {
for _, then := range cfgObj.Then {
conns, ok := i.Connections[cfgObj.UID]
if !ok {
i.Connections[cfgObj.UID] = []Connection{}
}
// Find the UID for the object we're connecting to.
var uid string
for _, cfgObj := range c.Objects {
if cfgObj.Name == then.Object {
uid = cfgObj.UID
break
}
}
if uid == "" {
return nil, fmt.Errorf("Could not find object %q", then.Object)
}
i.Connections[cfgObj.UID] = append(conns, Connection{
To: uid,
})
}
}
// Build workflow objects.
for _, cfgObj := range c.Objects {
obj := cfgObj.ToWorkflowConfig()
i.Objects = append(i.Objects, obj)
}
i.buildUIData()
return &i, nil
}
// Connection is a line between two objects.
type Connection struct {
To string `plist:"destinationuid,omitempty"`
Modifiers int64 `plist:"modifiers,omitempty"`
ModifierSubtext string `plist:"modifiersubtext,omitempty"`
VetoClose bool `plist:"vitoclose,omitempty"` // NOTE: Yes, "vitoclose"
}
// Object is an object in an Alfred workflow.
type Object struct {
Config Config `plist:"config,omitempty"`
Type string `plist:"type,omitempty"`
UID string `plist:"uid,omitempty"`
Version int64 `plist:"version,omitempty"`
}
// Config is a generic object configuration object.
type Config map[string]interface{}