forked from nsec/the-internet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (56 loc) · 1.4 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
package main
import (
"flag"
"fmt"
"os"
"github.com/lxc/lxd"
)
func main() {
err := run()
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
os.Exit(0)
}
func run() error {
// Usage
if len(os.Args) == 1 {
fmt.Fprintf(os.Stderr, "Usage: %s create <path> [-auto-start]\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s destroy\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s generate-map <path>\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s generate-dns <format>\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s start\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s status\n", os.Args[0])
fmt.Fprintf(os.Stderr, " %s stop\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\nArguments:\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "\n")
return fmt.Errorf("A command must be provided.")
}
// Parse the arguments
flag.Parse()
// Connect to LXD
c, err := lxd.NewClient(&lxd.DefaultConfig, "local")
if err != nil {
return err
}
// Commands
switch os.Args[1] {
case "create":
return cmdCreate(c, os.Args[2:])
case "destroy":
return cmdDestroy(c, os.Args[2:])
case "generate-map":
return cmdGenerateMap(c, os.Args[2:])
case "generate-dns":
return cmdGenerateDNS(c, os.Args[2:])
case "start":
return cmdStart(c, os.Args[2:])
case "status":
return cmdStatus(c, os.Args[2:])
case "stop":
return cmdStop(c, os.Args[2:])
}
return nil
}