-
Notifications
You must be signed in to change notification settings - Fork 20
/
runstatus_service_create.go
59 lines (46 loc) · 1.24 KB
/
runstatus_service_create.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
package cmd
import (
"fmt"
"os"
"github.com/exoscale/egoscale"
"github.com/spf13/cobra"
)
// runstatusServiceCreateCmd represents the create command
var runstatusServiceCreateCmd = &cobra.Command{
Use: "create [page name] <name>",
Short: "Create a service",
Aliases: gCreateAlias,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return cmd.Usage()
}
pageName := gCurrentAccount.DefaultRunstatusPage
serviceName := args[0]
if gCurrentAccount.DefaultRunstatusPage == "" && len(args) == 1 {
fmt.Fprintf(os.Stderr, `Error: No default runstat.us page is set:
Please specify a page in parameter or add it to %q
`, gConfigFilePath)
return cmd.Usage()
}
if len(args) > 1 {
pageName = args[0]
serviceName = args[1]
}
runstatusPage, err := csRunstatus.GetRunstatusPage(gContext, egoscale.RunstatusPage{Subdomain: pageName})
if err != nil {
return err
}
s, err := csRunstatus.CreateRunstatusService(gContext, egoscale.RunstatusService{
PageURL: runstatusPage.URL,
Name: serviceName,
})
if err != nil {
return err
}
fmt.Printf("Service %q successfully created\n", s.Name)
return nil
},
}
func init() {
runstatusServiceCmd.AddCommand(runstatusServiceCreateCmd)
}