-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplugin-data.go
73 lines (65 loc) · 1.93 KB
/
plugin-data.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
package goforjj
import (
"encoding/json"
"fmt"
)
// REST API json data
type PluginData struct {
Repos map[string]PluginRepo `json:",omitempty"` // List of repository data
Services PluginService `json:",omitempty"` // web service url. ex: https://github.hpe.com
Status string // Status message
CommitMessage string `json:",omitempty"` // Action commit message for Create/Update
ErrorMessage string // Found only if error detected
Files map[string][]string `json:",omitempty"` // List of files managed by the plugin
Options map[string]PluginOption `json:",omitempty"` // List of options needed at maintain use case, returned from create/update. Usually used to provide credentials.
}
const (
FilesSource = "source"
FilesDeploy = "deploy"
)
// AddFile add a file the list of files Forjj will take care in GIT.
//
func (d *PluginData) AddFile(where, file string) {
if where == "" {
where = FilesDeploy
}
if where != FilesDeploy && where != FilesSource {
where = FilesDeploy
}
if d.Files == nil {
d.Files = make(map[string][]string)
}
if v, found := d.Files[where]; !found {
v = make([]string, 1, 5)
v[0] = file
d.Files[where] = v
} else {
v = append(v, file)
d.Files[where] = v
}
}
// JsonPrint to print out json data
func (p *PluginResult) JsonPrint() error {
if b, err := json.Marshal(p); err != nil {
return err
} else {
fmt.Printf("%s\n", b)
}
return nil
}
// StatusAdd Add status information to the API caller.
func (o *PluginData) StatusAdd(n string, args ...interface{}) string {
if o.Status != "" {
o.Status += "\n"
}
s := fmt.Sprintf(n, args...)
o.Status += s
return s
}
// Errorf to store error message made by all other functions and return it to the
// API caller
func (o *PluginData) Errorf(s string, args ...interface{}) string {
s = fmt.Sprintf(s, args...)
o.ErrorMessage = s
return s
}