package app import ( "os" "path" "strings" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/pkg/autocomplete" "coopcloud.tech/abra/pkg/config" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) var appCheckCommand = &cli.Command{ Name: "check", Usage: "Check if app is configured correctly", Aliases: []string{"c"}, ArgsUsage: "", Action: func(c *cli.Context) error { app := internal.ValidateApp(c) 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) } logrus.Fatal(err) } envSample, err := config.ReadEnv(envSamplePath) if err != nil { logrus.Fatal(err) } var missing []string for k := range envSample { if _, ok := app.Env[k]; !ok { missing = append(missing, k) } } if len(missing) > 0 { missingEnvVars := strings.Join(missing, ", ") logrus.Fatalf("%s is missing %s", app.Path, missingEnvVars) } logrus.Infof("all necessary environment variables defined for %s", app.Name) return nil }, BashComplete: autocomplete.AppNameComplete, }