-
Notifications
You must be signed in to change notification settings - Fork 12
/
command_sync.go
65 lines (54 loc) · 1.52 KB
/
command_sync.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
package main
import (
"fmt"
"github.com/webdevops/go-sync/sync"
)
type SyncCommand struct {
AbstractCommand
Positional struct {
Server string `description:"server configuration key"`
} `positional-args:"true"`
Dump bool `long:"dump" description:"dump configuration as yaml"`
OnlyFilesystem bool `long:"filesystem" description:"sync only filesystem"`
OnlyDatabase bool `long:"database" description:"sync only database"`
SkipExec bool `long:"skip-exec" description:"skip execution"`
}
// Run sync command
func (command *SyncCommand) Execute(args []string) error {
config := command.GetConfig()
server := command.getServerSelectionFromUser(config, "sync", command.Positional.Server)
confServer, err := config.GetSyncServer(server)
if err != nil {
Logger.FatalErrorExit(3, err)
}
Logger.Step("using Server[%s]", server)
Logger.Step("using %s", confServer.Connection.GetInstance().String())
confServer.SetRunConfiguration(command.buildSyncRunConfig())
// --dump
if command.Dump {
fmt.Println()
fmt.Println(confServer.AsYaml())
} else {
confServer.Sync()
Logger.Println("-> finished")
}
return nil
}
func (command *SyncCommand) buildSyncRunConfig() (conf sync.RunConfiguration) {
// Init
conf.Exec = true
conf.Database = true
conf.Filesystem = true
if command.OnlyFilesystem {
conf.Database = false
conf.Filesystem = true
}
if command.OnlyDatabase {
conf.Database = true
conf.Filesystem = false
}
if command.SkipExec {
conf.Exec = false
}
return
}