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

@ -3,6 +3,7 @@ package internal
import (
"errors"
"coopcloud.tech/abra/pkg/app"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/recipe"
"github.com/sirupsen/logrus"
@ -25,21 +26,17 @@ func ValidateRecipeArg(c *cli.Context) string {
}
// ValidateAppNameArg ensures the app name arg is valid.
func ValidateAppNameArg(c *cli.Context) string {
func ValidateApp(c *cli.Context) config.App {
appName := c.Args().First()
if appName == "" {
ShowSubcommandHelpAndError(c, errors.New("no app provided"))
}
appFiles, err := config.LoadAppFiles("")
app, err := app.Get(appName)
if err != nil {
logrus.Fatal(err)
}
if _, ok := appFiles[appName]; !ok {
logrus.Fatalf("'%s' doesn't exist?", appName)
}
return appName
return app
}