forked from garetht/amanar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intellij_run_config_flow.go
74 lines (59 loc) · 1.74 KB
/
intellij_run_config_flow.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
package amanar
import (
"io/ioutil"
"log"
"path/filepath"
)
// UpdateUsername - must not have side effects
// UpdatePassword - must not have side effects
// In the database these actions are simply queued for later execution
// Persist
func NewIntellijRunConfigsFlow(config *IntellijRunConfiguration) (*IntellijRunConfigsFlow, error) {
files, err := ioutil.ReadDir(config.RunConfigurationsFolderPath)
if err != nil {
return nil, err
}
rcs := []*IntellijRunConfig{}
for _, file := range files {
if name := file.Name(); filepath.Ext(name) == ".xml" && !file.IsDir() {
fullPath := filepath.Join(config.RunConfigurationsFolderPath, name)
rc, err := NewIntellijRunConfig(fullPath)
if err != nil {
log.Printf("[RUN CONFIGS] Could not parse run config %s. Skipping.", fullPath)
} else {
rcs = append(rcs, rc)
}
}
}
return &IntellijRunConfigsFlow{
IntellijRunConfiguration: *config,
runConfigurations: rcs,
}, nil
}
type IntellijRunConfigsFlow struct {
IntellijRunConfiguration
credentials *Credentials
runConfigurations []*IntellijRunConfig
}
func (rc *IntellijRunConfigsFlow) Name() string {
return "INTELLIJ RUN CONFIGURATION"
}
func (rc *IntellijRunConfigsFlow) UpdateWithCredentials(credentials *Credentials) (err error) {
rc.credentials = credentials
for _, runConfig := range rc.runConfigurations {
runConfig.UpdateEnvironmentVariable(rc.EnvironmentVariable, rc.DatabaseHost, credentials)
}
return nil
}
func (rc *IntellijRunConfigsFlow) PersistChanges() (err error) {
if err != nil {
return
}
for _, runConfig := range rc.runConfigurations {
err = runConfig.WriteToFile()
if err != nil {
log.Printf("[RUN CONFIGS] Error writing %s to file. Skipping.", runConfig.Fullpath)
}
}
return nil
}