-
Notifications
You must be signed in to change notification settings - Fork 38
/
main.go
145 lines (127 loc) · 4.79 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package main
import (
"os"
"github.com/spf13/cobra"
)
// GitCommit is empty unless set as a build flag
// See https://blog.alexellis.io/inject-build-time-vars-golang/
var gitBranch string
var gitCommit string
func stringSliceContains(stringSlice []string, value string) bool {
for _, x := range stringSlice {
if value == x {
return true
}
}
return false
}
func main() {
root := cobra.Command{
Use: "milmove [flags]",
Short: "Webserver for MilMove",
Long: "Webserver for MilMove",
}
root.AddCommand(&cobra.Command{
Use: "version",
Short: "Print version information to stdout",
Long: "Print version information to stdout",
RunE: versionFunction,
SilenceUsage: true,
})
serveCommand := &cobra.Command{
Use: "serve",
Short: "Runs MilMove webserver",
Long: "Runs MilMove webserver",
RunE: serveFunction,
SilenceUsage: true,
}
initServeFlags(serveCommand.Flags())
root.AddCommand(serveCommand)
healthCommand := &cobra.Command{
Use: "health",
Short: "Checks the health of the MilMove server",
Long: "Checks the health of the MilMove server",
RunE: healthFunction,
SilenceUsage: true,
}
initServeFlags(healthCommand.Flags())
root.AddCommand(healthCommand)
migrateCommand := &cobra.Command{
Use: "migrate",
Short: "Runs MilMove migrations",
Long: "Runs MilMove migrations",
RunE: migrateFunction,
SilenceUsage: true, // not needed
SilenceErrors: true, // not needed
}
initMigrateFlags(migrateCommand.Flags())
root.AddCommand(migrateCommand)
genCommand := &cobra.Command{
Use: "gen",
Short: "Generate migrations and other objects",
Long: "Generate migrations and other objects",
RunE: nil,
}
root.AddCommand(genCommand)
genMigrationCommand := &cobra.Command{
Use: "migration -n NAME [-t TYPE]",
Short: "Generate migrations and other objects",
Long: "Generate migrations and other objects",
RunE: genMigrationFunction,
DisableFlagsInUseLine: true,
SilenceErrors: true, // not needed
}
initGenMigrationFlags(genMigrationCommand.Flags())
genCommand.AddCommand(genMigrationCommand)
genCertsMigrationCommand := &cobra.Command{
Use: "certs-migration [ -f FINGERPRINT -s SUBJECT | --cac ] -n MIGRATION_NAME",
Short: "Generate migrations required for adding client certificates",
Long: "Generate migrations required for adding client certificates",
RunE: genCertsMigration,
DisableFlagsInUseLine: true,
SilenceErrors: true, // not needed
}
initGenCertsMigrationFlags(genCertsMigrationCommand.Flags())
genCommand.AddCommand(genCertsMigrationCommand)
genDisableCertsMigrationCommand := &cobra.Command{
Use: "disable-certs-migration [ -f FINGERPRINT ] -n MIGRATION_NAME",
Short: "Generate migrations required for removing client certificates",
Long: "Generate migrations required for removing client certificates",
RunE: genDisableCertsMigration,
DisableFlagsInUseLine: true,
SilenceErrors: true, // not needed
}
initGenDisableCertsMigrationFlags(genDisableCertsMigrationCommand.Flags())
genCommand.AddCommand(genDisableCertsMigrationCommand)
genDutyStationsMigrationCommand := &cobra.Command{
Use: "duty-stations-migration -f CSV_FILENAME -n MIGRATION_NAME",
Short: "Generate migrations required for adding duty stations",
Long: "Generate migrations required for adding duty stations",
RunE: genDutyStationsMigration,
DisableFlagsInUseLine: true,
SilenceErrors: true, // not needed
}
initGenDutyStationsMigrationFlags(genDutyStationsMigrationCommand.Flags())
genCommand.AddCommand(genDutyStationsMigrationCommand)
genDisableUserMigrationCommand := &cobra.Command{
Use: "disable-user-migration -e EMAIL",
Short: "Generate migrations required for disabling a user",
Long: "Generate migrations required for disabling a user",
RunE: genDisableUserMigration,
DisableFlagsInUseLine: true,
}
initDisableUserMigrationFlags(genDisableUserMigrationCommand.Flags())
genCommand.AddCommand(genDisableUserMigrationCommand)
completionCommand := &cobra.Command{
Use: "completion",
Short: "Generates bash completion scripts",
Long: "To install completion scripts run:\n\nmilmove completion > /usr/local/etc/bash_completion.d/milmove",
RunE: func(_ *cobra.Command, _ []string) error {
return root.GenBashCompletion(os.Stdout)
},
}
root.AddCommand(completionCommand)
if err := root.Execute(); err != nil {
panic(err)
}
}