-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
86 lines (78 loc) · 2.53 KB
/
config.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
package accountsync
import (
"fmt"
"github.com/codegangsta/cli"
)
var (
EncryptionKeyFlag = &cli.StringFlag{
Name: "k, encryption-key",
Value: "",
EnvVar: "TRAVIS_ACCOUNT_SYNC_ENCRYPTION_KEY",
}
DatabaseURLFlag = &cli.StringFlag{
Name: "d, database-url",
Value: "",
EnvVar: "TRAVIS_ACCOUNT_SYNC_DATABASE_URL",
}
GithubUsernamesFlag = &cli.StringSliceFlag{
Name: "u, github-usernames",
Value: &cli.StringSlice{},
EnvVar: "TRAVIS_ACCOUNT_SYNC_GITHUB_USERNAMES",
}
OrganizationsRepositoriesLimitFlag = &cli.IntFlag{
Name: "organizations-repositories-limit",
Value: 1000,
EnvVar: "TRAVIS_ACCOUNT_SYNC_ORGANIZATIONS_REPOSITORIES_LIMIT",
}
RepositoriesStartPageFlag = &cli.IntFlag{
Name: "repositories-start-page",
Value: 1,
EnvVar: "TRAVIS_ACCOUNT_SYNC_REPOSITORIES_START_PAGE",
}
SyncTypesFlag = &cli.StringSliceFlag{
Name: "T, sync-types",
Value: &cli.StringSlice{"public"},
EnvVar: "TRAVIS_ACCOUNT_SYNC_TYPES",
}
SyncCacheSizeFlag = &cli.IntFlag{
Name: "sync-cache-size",
Value: 64,
EnvVar: "TRAVIS_ACCOUNT_SYNC_CACHE_SIZE",
}
Flags = []cli.Flag{
*EncryptionKeyFlag,
*DatabaseURLFlag,
*GithubUsernamesFlag,
*OrganizationsRepositoriesLimitFlag,
*RepositoriesStartPageFlag,
*SyncTypesFlag,
*SyncCacheSizeFlag,
}
errPrivateSyncNotSupported = fmt.Errorf("private sync is not supported (yet)!")
)
type Config struct {
EncryptionKey string `cfg:"encryption-key"` // TODO: do something with these tags
DatabaseURL string `cfg:"database-url"`
GithubUsernames []string `cfg:"github-usernames"`
OrganizationsRepositoriesLimit int `cfg:"organizations-repositories-limit"`
RepositoriesStartPage int `cfg:"repositories-start-page"`
SyncTypes []string `cfg:"sync-types"`
SyncCacheSize int `cfg:"sync-cache-size"`
}
func NewConfig(c *cli.Context) *Config {
return &Config{
DatabaseURL: c.String("database-url"),
EncryptionKey: c.String("encryption-key"),
GithubUsernames: c.StringSlice("github-usernames"),
OrganizationsRepositoriesLimit: c.Int("organizations-repositories-limit"),
RepositoriesStartPage: c.Int("repositories-start-page"),
SyncTypes: c.StringSlice("sync-types"),
SyncCacheSize: c.Int("sync-cache-size"),
}
}
func (cfg *Config) Validate() error {
if sliceContains(cfg.SyncTypes, "private") {
return errPrivateSyncNotSupported
}
return nil
}