refactor: use app getting instead of boilerplate

This commit is contained in:
2021-09-05 23:17:35 +02:00
parent 48bcc9cb36
commit d4333c2dc0
18 changed files with 111 additions and 266 deletions

View File

@ -17,19 +17,9 @@ var appCheckCommand = &cli.Command{
Aliases: []string{"c"},
ArgsUsage: "<service>",
Action: func(c *cli.Context) error {
appName := internal.ValidateAppNameArg(c)
app := internal.ValidateApp(c)
appFiles, err := config.LoadAppFiles("")
if err != nil {
logrus.Fatal(err)
}
appEnv, err := config.GetApp(appFiles, appName)
if err != nil {
logrus.Fatal(err)
}
envSamplePath := path.Join(config.ABRA_DIR, "apps", appEnv.Type, ".env.sample")
envSamplePath := path.Join(config.ABRA_DIR, "apps", app.Type, ".env.sample")
if _, err := os.Stat(envSamplePath); err != nil {
if os.IsNotExist(err) {
logrus.Fatalf("'%s' does not exist?", envSamplePath)
@ -44,15 +34,14 @@ var appCheckCommand = &cli.Command{
var missing []string
for k := range envSample {
if _, ok := appEnv.Env[k]; !ok {
if _, ok := app.Env[k]; !ok {
missing = append(missing, k)
}
}
if len(missing) > 0 {
path := appFiles[appName].Path
missingEnvVars := strings.Join(missing, ", ")
logrus.Fatalf("%s is missing %s", path, missingEnvVars)
logrus.Fatalf("%s is missing %s", app.Path, missingEnvVars)
}
logrus.Info("All necessary environment variables defined")