-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.go
More file actions
77 lines (58 loc) · 1.75 KB
/
update.go
File metadata and controls
77 lines (58 loc) · 1.75 KB
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
75
76
77
package main
import (
"github.com/spf13/cobra"
"log"
)
var updateCmd = &cobra.Command{
Use: "update",
Short: "update attributes of a BitBalloon site",
Long: "update attributes of a BitBalloon site. Name, domain, password and notification email can be updated.",
}
type updateString struct {
value string
set bool
}
func (u *updateString) Set(value string) error {
u.value = value
u.set = true
return nil
}
func (u *updateString) String() string {
return u.value
}
var updateName, updateDomain, updatePassword, updateEmail updateString
func init() {
updateCmd.Run = update
updateCmd.Flags().StringVarP(&SiteId, "site", "s", "", "site domain or id")
updateCmd.Flags().VarP(&updateName, "name", "n", "Name of the site (must be a valid subdomain: <name>.bitballoon.com)")
updateCmd.Flags().VarP(&updateDomain, "domain", "d", "Custom domain for the site (only works for premium sites)")
updateCmd.Flags().VarP(&updatePassword, "password", "", "Password for the site")
updateCmd.Flags().VarP(&updateEmail, "email", "e", "Notification email for form submissions (only works for premium sites)")
}
func update(cmd *cobra.Command, args []string) {
client := newClient()
if SiteId == "" {
log.Fatalln("No site id specified. Use the --site options")
}
site, _, err := client.Sites.Get(SiteId)
if err != nil {
log.Fatalf("Error updating site: %v", err)
}
if updateName.set {
site.Name = updateName.value
}
if updateDomain.set {
site.CustomDomain = updateDomain.value
}
if updatePassword.set {
site.Password = updatePassword.value
}
if updateEmail.set {
site.NotificationEmail = updateEmail.value
}
_, err = site.Update()
if err != nil {
log.Fatalf("Error updating site: %v", err)
}
log.Printf("Site updated. URL: %v", site.Url)
}