fix: get app new working again

This commit is contained in:
decentral1se 2021-09-07 08:12:37 +02:00
parent 87f0985ebb
commit b477bf8ece
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
3 changed files with 24 additions and 20 deletions

View File

@ -1,7 +1,6 @@
package app package app
import ( import (
"errors"
"fmt" "fmt"
"path" "path"
@ -9,7 +8,7 @@ import (
"coopcloud.tech/abra/cli/internal" "coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/catalogue" "coopcloud.tech/abra/pkg/catalogue"
"coopcloud.tech/abra/pkg/config" "coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/recipe" recipePkg "coopcloud.tech/abra/pkg/recipe"
"coopcloud.tech/abra/pkg/secret" "coopcloud.tech/abra/pkg/secret"
"github.com/AlecAivazis/survey/v2" "github.com/AlecAivazis/survey/v2"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -81,22 +80,23 @@ var appNewCommand = &cli.Command{
Action: action, Action: action,
} }
// getRecipe retrieves a recipe from the recipe catalogue. // getRecipeMeta retrieves the recipe metadata from the recipe catalogue.
func getRecipe(recipeName string) (catalogue.RecipeMeta, error) { func getRecipeMeta(recipeName string) (catalogue.RecipeMeta, error) {
catl, err := catalogue.ReadRecipeCatalogue() catl, err := catalogue.ReadRecipeCatalogue()
if err != nil { if err != nil {
return catalogue.RecipeMeta{}, err return catalogue.RecipeMeta{}, err
} }
rec, ok := catl[recipeName] recipeMeta, ok := catl[recipeName]
if !ok { if !ok {
return catalogue.RecipeMeta{}, fmt.Errorf("recipe '%s' does not exist?", recipeName) err := fmt.Errorf("recipe '%s' does not exist?", recipeName)
return catalogue.RecipeMeta{}, err
} }
if err := recipe.EnsureExists(rec.Name); err != nil { if err := recipePkg.EnsureExists(recipeMeta.Name); err != nil {
return catalogue.RecipeMeta{}, err return catalogue.RecipeMeta{}, err
} }
return rec, nil return recipeMeta, nil
} }
// ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/ // ensureDomainFlag checks if the domain flag was used. if not, asks the user for it/
@ -172,26 +172,22 @@ func createSecrets(sanitisedAppName string) (secrets, error) {
// action is the main command-line action for this package // action is the main command-line action for this package
func action(c *cli.Context) error { func action(c *cli.Context) error {
recipeName := c.Args().First() recipe := internal.ValidateRecipe(c)
if recipeName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
if err := config.EnsureAbraDirExists(); err != nil { if err := config.EnsureAbraDirExists(); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
rec, err := getRecipe(recipeName) recipeMeta, err := getRecipeMeta(recipe.Name)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
latestVersion := rec.LatestVersion() latestVersion := recipeMeta.LatestVersion()
if err := recipe.EnsureVersion(latestVersion); err != nil { if err := recipePkg.EnsureVersion(recipe.Name, latestVersion); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
// These use the flag from internal.x to check and edit so no need to return anything
if err := ensureServerFlag(); err != nil { if err := ensureServerFlag(); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -209,7 +205,7 @@ func action(c *cli.Context) error {
logrus.Fatalf("'%s' cannot be longer than 45 characters", sanitisedAppName) logrus.Fatalf("'%s' cannot be longer than 45 characters", sanitisedAppName)
} }
if err := config.CopyAppEnvSample(recipeName, newAppName, newAppServer); err != nil { if err := config.CopyAppEnvSample(recipe.Name, newAppName, newAppServer); err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -229,7 +225,7 @@ func action(c *cli.Context) error {
tableCol := []string{"Name", "Domain", "Type", "Server"} tableCol := []string{"Name", "Domain", "Type", "Server"}
table := abraFormatter.CreateTable(tableCol) table := abraFormatter.CreateTable(tableCol)
table.Append([]string{sanitisedAppName, domain, recipeName, newAppServer}) table.Append([]string{sanitisedAppName, domain, recipe.Name, newAppServer})
defer table.Render() defer table.Render()
return nil return nil

View File

@ -65,6 +65,14 @@ var appSecretGenerateCommand = &cli.Command{
} }
} }
tableCol := []string{"Name", "Value"}
table := abraFormatter.CreateTable(tableCol)
for name, val := range secretVals {
table.Append([]string{name, val})
}
table.Render()
logrus.Warn("Warning, these secrets will not be shown again, please take note of them *now*")
return nil return nil
}, },
} }

View File

@ -86,8 +86,8 @@ func EnsureExists(recipe string) error {
} }
// EnsureVersion checks whether a specific version exists for a recipe. // EnsureVersion checks whether a specific version exists for a recipe.
func EnsureVersion(version string) error { func EnsureVersion(recipeName, version string) error {
recipeDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(version)) recipeDir := path.Join(config.ABRA_DIR, "apps", recipeName)
repo, err := git.PlainOpen(recipeDir) repo, err := git.PlainOpen(recipeDir)
if err != nil { if err != nil {