refactor: centralise app name validation
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -3,6 +3,7 @@ package internal
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -22,3 +23,23 @@ func ValidateRecipeArg(c *cli.Context) string {
|
||||
|
||||
return recipeName
|
||||
}
|
||||
|
||||
// ValidateAppNameArg ensures the app name arg is valid.
|
||||
func ValidateAppNameArg(c *cli.Context) string {
|
||||
appName := c.Args().First()
|
||||
|
||||
if appName == "" {
|
||||
ShowSubcommandHelpAndError(c, errors.New("no app provided"))
|
||||
}
|
||||
|
||||
appFiles, err := config.LoadAppFiles("")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
|
||||
if _, ok := appFiles[appName]; !ok {
|
||||
logrus.Fatalf("'%s' doesn't exist?", appName)
|
||||
}
|
||||
|
||||
return appName
|
||||
}
|
||||
|
Reference in New Issue
Block a user