-
Notifications
You must be signed in to change notification settings - Fork 12
/
command.go
73 lines (57 loc) · 1.42 KB
/
command.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 main
import (
"strings"
"os"
"fmt"
"path"
"github.com/webdevops/go-sync/sync"
"gopkg.in/AlecAivazis/survey.v1"
)
type AbstractCommand struct {
}
func (command *AbstractCommand) GetConfig() *sync.SyncConfig {
Logger.Main("Initialisation")
configFile := command.findConfigFile()
if configFile == "" {
Logger.FatalExit(2, "Unable to find configuration file (searched %s)", strings.Join(validConfigFiles, " "))
}
Logger.Step("found configuration file %s", configFile)
sync.Logger = Logger
config := sync.NewConfigParser(configFile)
return config
}
func (command *AbstractCommand) findConfigFile() string {
pwd, err := os.Getwd()
if err != nil {
Logger.FatalErrorExit(1, err)
fmt.Println(err)
}
for true {
for _, filename := range validConfigFiles {
filepath := path.Join(pwd, filename)
if sync.FileExists(filepath) {
return filepath
}
}
// already found root, we finished here
if pwd == "/" {
break
}
pwd = path.Dir(pwd)
// oh, path seems to be empty.. stopping here now
if pwd == "." || pwd == "" {
break
}
}
return ""
}
func (command *AbstractCommand) getServerSelectionFromUser(config *sync.SyncConfig, confType string, userSelection string) string {
if userSelection == "" {
prompt := &survey.Select{
Message: "Choose configuration:",
Options: config.GetServerList(confType),
}
survey.AskOne(prompt, &userSelection, nil)
}
return userSelection
}