-
Notifications
You must be signed in to change notification settings - Fork 0
/
fx.go
88 lines (72 loc) · 1.37 KB
/
fx.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
package main
import (
"flag"
"fmt"
"os"
"github.com/metrue/fx/commands"
"github.com/metrue/fx/server"
)
const version string = "0.0.2"
const usage = `Usage:
$ fx up func1 func2 ... deploy a function or a group of functions
$ fx down func1 func2 ... destroy a function or a group of functions
$ fx list list deployed services
$ fx serve manage fx server
$ fx --version show current version of f(x)
`
func versionAndExit() {
fmt.Println(version)
os.Exit(0)
}
func helpAndExit() {
fmt.Print(usage)
os.Exit(0)
}
func parseFlags() (version bool, help bool, verbose bool) {
helpPtr := flag.Bool(
"help",
false,
"Help information.",
)
versionPtr := flag.Bool(
"version",
false,
"Version information.",
)
verbosePtr := flag.Bool(
"verbose",
false,
"Make the operation more talkative",
)
flag.Parse()
version = *versionPtr
help = *helpPtr
verbose = *verbosePtr
return version, help, verbose
}
func main() {
nArgs := len(os.Args)
if nArgs < 2 {
helpAndExit()
}
version, help, verbose := parseFlags()
if help {
helpAndExit()
}
if version {
versionAndExit()
}
switch os.Args[1] {
case "serve":
server.Start(verbose)
case "up":
commands.Up()
case "down":
commands.Down()
case "list":
commands.List()
default:
fmt.Print(usage)
os.Exit(1)
}
}