-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync.go
57 lines (46 loc) · 1.39 KB
/
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
package cmd
import (
"github.com/renehernandez/appfile/internal/errors"
"github.com/renehernandez/appfile/internal/log"
"github.com/spf13/cobra"
)
type syncCmd struct {
*rootCmd
}
var (
syncLong = `Sync all resources from app platform specs to DigitalOcean
If there is no app with the existing name, a new app will be create.
Otherwise the existing app will be updated with the changes in the spec.
`
syncExample = ` # Sync using defaults: appfile.yaml in current location, default environment and DIGITALOCEAN_ACCESS_TOKEN env var
appfile sync
# Sync using appfile.yaml in custom location, review environment and access token option
appfile sync --file /path/to/appfile.yaml --environment review --access-token $TOKEN
# Sync with debug output
appfile sync --log-level debug`
)
func newSyncCmd(rootCmd *rootCmd) *cobra.Command {
sync := syncCmd{
rootCmd: rootCmd,
}
cmd := &cobra.Command{
Use: "sync",
Short: "Sync all resources from app platform specs to DigitalOcean",
Long: syncLong,
Example: syncExample,
Run: func(cmd *cobra.Command, args []string) {
sync.run()
},
}
return cmd
}
func (sync *syncCmd) run() {
appfile := sync.appfileFromSpec()
err := appfile.Sync()
errors.CheckAndFail(err)
for _, spec := range appfile.AppSpecs {
for _, domain := range spec.Domains {
log.Infof("%s app will be accessible at %s", spec.Name, domain.Domain)
}
}
}