feat: implement check command

This commit is contained in:
decentral1se 2021-08-28 20:13:56 +02:00
parent 23737ed3a7
commit 8ad51c1fd5
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 61 additions and 3 deletions

View File

@ -16,7 +16,7 @@
- [x] `new`
- [x] `backup`
- [ ] `deploy` (WIP: decentral1se)
- [ ] `check` (WIP: decentral1se)
- [x] `check`
- [x] `version`
- [ ] `config`
- [ ] `cp`

View File

@ -1,7 +1,65 @@
package app
import "github.com/urfave/cli/v2"
import (
"errors"
"fmt"
"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",
Name: "check",
ArgsUsage: "<service>",
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 := fmt.Sprintf(strings.Join(missing, ", "))
logrus.Fatalf("%s is missing %s", path, missingEnvVars)
}
logrus.Info("All necessary environment variables defined")
return nil
},
}