/
create.go
43 lines (38 loc) · 950 Bytes
/
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
package topology
import (
"fmt"
"gopkg.in/sensorbee/sensorbee.v0/client"
"gopkg.in/urfave/cli.v1"
)
func setUpCreate() cli.Command {
return cli.Command{
Name: "create",
Aliases: []string{"c"},
Usage: "create a new topology",
Description: "sensorbee topology create <topology_name> create a new topology having <topology_name>.",
Action: actionWrapper(runCreate),
Flags: commonFlags,
}
}
func runCreate(c *cli.Context) error {
if err := validateFlags(c); err != nil {
return err
}
args := c.Args()
switch l := len(args); l {
case 1:
// ok
case 0:
return fmt.Errorf("topology_name is missing")
default:
return fmt.Errorf("too many command line arguments")
}
res, err := do(c, client.Post, "topologies", map[string]interface{}{
"name": args[0],
}, "Cannot create a topology")
if err != nil {
return err
}
// TODO: show something about the created topology
return res.Close()
}