/
drop.go
47 lines (42 loc) · 1.11 KB
/
drop.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
package topology
import (
"fmt"
"gopkg.in/sensorbee/sensorbee.v0/client"
"gopkg.in/sensorbee/sensorbee.v0/core"
"gopkg.in/urfave/cli.v1"
"path"
)
func setUpDrop() cli.Command {
return cli.Command{
Name: "drop",
Aliases: []string{"d"},
Usage: "drop an existing topology",
Description: "sensorbee topology drop <topology_name> drops an existing topology having <topology_name>",
Action: actionWrapper(runDrop),
Flags: commonFlags,
}
}
func runDrop(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")
}
name := args[0]
if err := core.ValidateSymbol(name); err != nil {
// This is checked here to avoid sending wrong DELETE request to different URL.
return fmt.Errorf("The name of the topology is invalid: %v", err)
}
res, err := do(c, client.Delete, path.Join("topologies", name), nil, "Cannot drop a topology")
if err != nil {
return err
}
return res.Close()
}