package app import ( "errors" "os" "path" "strings" "coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/config" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) var appCheckCommand = &cli.Command{ Name: "check", ArgsUsage: "", Action: func(c *cli.Context) error { appName := c.Args().First() if appName == "" { internal.ShowSubcommandHelpAndError(c, errors.New("no app name provided")) } 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") 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 := appEnv.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.Info("All necessary environment variables defined") return nil }, }