From decfe095fef5133ccdfc5a64bd8382cd5508ddee Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Sat, 25 Dec 2021 14:51:53 +0100 Subject: [PATCH] feat: improved recipe creation --- cli/internal/common.go | 1 + cli/recipe/new.go | 65 ++++++++++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/cli/internal/common.go b/cli/internal/common.go index fe76421b..a0cac362 100644 --- a/cli/internal/common.go +++ b/cli/internal/common.go @@ -47,6 +47,7 @@ var ForceFlag = &cli.BoolFlag{ Name: "force", Value: false, Aliases: []string{"f"}, + Usage: "Perform action without further prompt. Use with care!", Destination: &Force, } diff --git a/cli/recipe/new.go b/cli/recipe/new.go index 7dbd19f7..a0016da6 100644 --- a/cli/recipe/new.go +++ b/cli/recipe/new.go @@ -14,6 +14,20 @@ import ( "github.com/urfave/cli/v2" ) +// recipeMetadata is the recipe metadata for the README.md +type recipeMetadata struct { + Name string + Description string + Category string + Status string + Image string + Healthcheck string + Backups string + Email string + Tests string + SSO string +} + var recipeNewCommand = &cli.Command{ Name: "new", Usage: "Create a new recipe", @@ -29,8 +43,6 @@ Abra uses our built-in example repository which is available here: Files within the example repository make use of the Golang templating system which Abra uses to inject values into the generated recipe folder (e.g. name of recipe and domain in the sample environment config). - -The new example repository is cloned to ~/.abra/apps/. `, Action: func(c *cli.Context) error { recipeName := c.Args().First() @@ -53,12 +65,13 @@ The new example repository is cloned to ~/.abra/apps/. if err := os.RemoveAll(gitRepo); err != nil { logrus.Fatal(err) } - logrus.Debugf("removed git repo in %s", gitRepo) + logrus.Debugf("removed example git repo in %s", gitRepo) + + meta := newRecipeMeta(recipeName) toParse := []string{ path.Join(config.RECIPES_DIR, recipeName, "README.md"), path.Join(config.RECIPES_DIR, recipeName, ".env.sample"), - path.Join(config.RECIPES_DIR, recipeName, ".drone.yml"), } for _, path := range toParse { file, err := os.OpenFile(path, os.O_RDWR, 0664) @@ -71,13 +84,7 @@ The new example repository is cloned to ~/.abra/apps/. logrus.Fatal(err) } - // TODO: ask for description and probably other things so that the - // template repository is more "ready" to go than the current best-guess - // mode of templating - if err := tpl.Execute(file, struct { - Name string - Description string - }{recipeName, "TODO"}); err != nil { + if err := tpl.Execute(file, meta); err != nil { logrus.Fatal(err) } } @@ -87,11 +94,39 @@ The new example repository is cloned to ~/.abra/apps/. logrus.Fatal(err) } - logrus.Infof( - "new recipe %s created in %s, happy hacking!\n", - recipeName, path.Join(config.RECIPES_DIR, recipeName), - ) + fmt.Print(fmt.Sprintf(` +Your new %s recipe has been created in %s. + +In order to share your recipe, you can upload it the git repository to: + + https://git.coopcloud.tech/coop-cloud/%s + +If you're not sure how to do that, come chat with us: + + https://docs.coopcloud.tech/contact + +See "abra recipe -h" for additional recipe maintainer commands. + +Happy Hacking! + +`, recipeName, path.Join(config.RECIPES_DIR, recipeName), recipeName)) return nil }, } + +// newRecipeMeta creates a new recipeMetadata instance with defaults +func newRecipeMeta(recipeName string) recipeMetadata { + return recipeMetadata{ + Name: recipeName, + Description: "", + Category: "", + Status: "", + Image: "", + Healthcheck: "", + Backups: "", + Email: "", + Tests: "", + SSO: "", + } +}