-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathroute_create.go
59 lines (52 loc) · 1.07 KB
/
route_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 main
import (
"fmt"
"log"
)
func init() {
register(&Command{
group: "Route",
name: "route.create",
help: "Create a route in current space",
params: []Param{
Param{name: "host", desc: "Host name"},
Param{name: "domain", desc: "Domain name"},
Param{name: "space", desc: "Space name"},
Param{name: "org", desc: "Organization name"},
},
handle: route_create,
})
}
func route_create() {
target, err := c.SelectedTarget()
if err != nil {
log.Fatal(err)
}
domains, err := target.DomainsGet()
if err != nil {
log.Fatal(err)
}
i, err := DomainList(domains).FindOrPick(params["domain"])
if err != nil {
log.Fatal(err)
}
domain := domains[i]
spaces := domain.Spaces
i, err = SpaceList(spaces).FindOrPick(params["space"], params["org"])
if err != nil {
log.Fatal(err)
}
space := spaces[i]
name, exists := params["host"]
if !exists {
fmt.Print("Host name: ")
_, err = fmt.Scanf("%s\n", &name)
if err != nil {
log.Fatal(err)
}
}
err = target.RouteCreate(name, domain.Guid, space.Guid)
if err != nil {
log.Fatal(err)
}
}