-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
79 lines (70 loc) · 2.06 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
package main
import (
config "github.com/poddworks/machine/config"
mach "github.com/poddworks/machine/lib/machine"
"github.com/poddworks/machine/driver/aws"
"github.com/poddworks/machine/driver/swarm"
"github.com/urfave/cli"
"fmt"
"math/rand"
"os"
"time"
)
const (
DEFAULT_CONFIG_DIR = "~/.machine"
DEFAULT_ORGANIZATION_PLACEMENT_NAME = "podd.org"
DEFAULT_MACHINE_PORT = "22"
)
func init() {
rand.Seed(time.Now().Unix())
}
func main() {
app := cli.NewApp()
app.Version = "1.2.0"
app.Name = "machine"
app.Usage = "Swiss Army knife for DevOps"
app.EnableBashCompletion = true
app.Authors = []cli.Author{
cli.Author{"Yi-Hung Jen", "yihungjen@gmail.com"},
}
app.Commands = []cli.Command{
CreateCommand(),
InstanceCommand("start", "Start"),
InstanceCommand("stop", "Stop"),
InstanceCommand("reboot", "Reboot"),
InstanceCommand("rm", "Remove And Terminate"),
ListInstanceCommand(),
IPCommand(),
EnvCommand(),
ExecCommand(),
SSHCommand(),
TlsCommand(),
DnstoolCommand(),
aws.NewCommand(),
swarm.NewCommand(),
RecipeCommand(),
}
app.Flags = []cli.Flag{
cli.StringFlag{Name: "user", EnvVar: "MACHINE_USER", Usage: "Run command as user"},
cli.StringFlag{Name: "cert", EnvVar: "MACHINE_CERT_FILE", Usage: "Private key to use in Authentication"},
cli.StringFlag{Name: "port", EnvVar: "MACHINE_PORT", Value: DEFAULT_MACHINE_PORT, Usage: "Connected to ssh port"},
cli.StringFlag{Name: "org", Value: DEFAULT_ORGANIZATION_PLACEMENT_NAME, Usage: "Organization for Self Signed CA"},
cli.StringFlag{Name: "confdir", Value: DEFAULT_CONFIG_DIR, Usage: "Configuration and Certificate path"},
}
app.Before = func(c *cli.Context) error {
if err := config.Parse(c); err != nil {
return cli.NewExitError("error/failed-to-parse-config", 1)
}
if err := mach.InstList.Load(); err != nil {
return cli.NewExitError("error/failed-to-load-cache-instance", 1)
}
return nil
}
app.BashComplete = func(c *cli.Context) {
// List available commands
for _, cmd := range app.Commands {
fmt.Fprint(c.App.Writer, " ", cmd.Name)
}
}
app.Run(os.Args)
}