-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (67 loc) · 1.75 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"errors"
"os"
"strconv"
"github.com/Zumata/capesize/config"
"github.com/Zumata/capesize/core"
"github.com/Zumata/capesize/services"
flags "github.com/jessevdk/go-flags"
)
type Options struct{}
var options Options
var parser = flags.NewParser(&options, flags.Default)
// Command: create
type CreateCommand struct {
}
var createCommand CreateCommand
func (c *CreateCommand) Execute(args []string) error {
if len(args) != 2 {
return errors.New("Please provide the provider and number of hosts to be spawned")
}
numHosts, err := strconv.Atoi(args[1])
if err != nil {
return errors.New("Please provide the number of hosts to be spawned")
}
provider := args[0]
err = config.FindProvider(provider)
if err != nil {
return errors.New("Specified provider is unknown.")
}
capesize := &core.Capesize{}
success := services.CreateInstances(capesize, provider, numHosts)
if !success {
return errors.New("Deployment Failed")
}
return nil
}
// Command: list
type ListCommand struct {
}
var listCommand ListCommand
func (c *ListCommand) Execute(args []string) error {
if len(args) != 1 {
return errors.New("Please provide the provider")
}
provider := args[0]
err := config.FindProvider(provider)
if err != nil {
return errors.New("Specified provider is unknown.")
}
capesize := &core.Capesize{}
services.ListInstances(capesize, provider)
return nil
}
func main() {
parser.AddCommand("create",
"Spawn docker hosts",
"The create command spawns a docker host. capesize create <provider> <num hosts>.",
&createCommand)
parser.AddCommand("list",
"List spawned docker hosts",
"The list command lists spawned docker hosts. capesize list.",
&listCommand)
if _, err := parser.Parse(); err != nil {
os.Exit(1)
}
}