-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
75 lines (69 loc) · 1.47 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
package main
import (
"log"
"os"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config-source",
EnvVar: "SIDEKICK_CONFIG_SOURCE",
Value: "dynamodb",
},
cli.StringFlag{
Name: "config-key",
EnvVar: "SIDEKICK_CONFIG_KEY",
Value: "common",
},
cli.StringFlag{
Name: "config-table",
EnvVar: "SIDEKICK_CONFIG_TABLE",
},
cli.StringFlag{
Name: "aws-endpoint",
EnvVar: "AWS_ENDPOINT",
Value: "http://localhost:4566",
},
cli.StringFlag{
Name: "aws-region",
EnvVar: "AWS_REGION",
Value: "us-east-1",
},
cli.StringSliceFlag{
Name: "env, e",
Usage: "set environment variables",
},
}
app.Before = func(c *cli.Context) error {
// TODO: support multiple config sources
var configSource ConfigSource
switch c.String("config-source") {
case "dynamodb":
configSource = &DynamoDBConfigSource{
Table: c.String("config-table"),
Key: c.String("config-key"),
Endpoint: c.String("aws-endpoint"),
Region: c.String("aws-region"),
}
default:
return cli.NewExitError("couldn't find that config source type", 2)
}
appendConfigSource(c, configSource)
envs := c.StringSlice("env")
if len(envs) > 0 {
appendConfigSource(c, NewStringSliceConfigSource(envs))
}
return nil
}
app.Commands = []cli.Command{
commandEnv,
commandRun,
commandStart,
}
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}