fix: docs and fix for new recipes

Closes coop-cloud/organising#228.
This commit is contained in:
decentral1se 2021-11-02 13:29:58 +01:00
parent c76bd25c1d
commit 7022f42711
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -1,6 +1,7 @@
package recipe
import (
"errors"
"fmt"
"os"
"path"
@ -18,10 +19,27 @@ var recipeNewCommand = &cli.Command{
Usage: "Create a new recipe",
Aliases: []string{"n"},
ArgsUsage: "<recipe>",
Action: func(c *cli.Context) error {
recipe := internal.ValidateRecipe(c)
Description: `
This command creates a new recipe.
directory := path.Join(config.APPS_DIR, recipe.Name)
Abra uses our built-in example repository which is available here:
https://git.coopcloud.tech/coop-cloud/example
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/<recipe>.
`,
Action: func(c *cli.Context) error {
recipeName := c.Args().First()
if recipeName == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe provided"))
}
directory := path.Join(config.APPS_DIR, recipeName)
if _, err := os.Stat(directory); !os.IsNotExist(err) {
logrus.Fatalf("'%s' recipe directory already exists?", directory)
}
@ -31,16 +49,16 @@ var recipeNewCommand = &cli.Command{
logrus.Fatal(err)
}
gitRepo := path.Join(config.APPS_DIR, recipe.Name, ".git")
gitRepo := path.Join(config.APPS_DIR, recipeName, ".git")
if err := os.RemoveAll(gitRepo); err != nil {
logrus.Fatal(err)
}
logrus.Debugf("removed git repo in '%s'", gitRepo)
toParse := []string{
path.Join(config.APPS_DIR, recipe.Name, "README.md"),
path.Join(config.APPS_DIR, recipe.Name, ".env.sample"),
path.Join(config.APPS_DIR, recipe.Name, ".drone.yml"),
path.Join(config.APPS_DIR, recipeName, "README.md"),
path.Join(config.APPS_DIR, recipeName, ".env.sample"),
path.Join(config.APPS_DIR, recipeName, ".drone.yml"),
}
for _, path := range toParse {
file, err := os.OpenFile(path, os.O_RDWR, 0755)
@ -59,14 +77,14 @@ var recipeNewCommand = &cli.Command{
if err := tpl.Execute(file, struct {
Name string
Description string
}{recipe.Name, "TODO"}); err != nil {
}{recipeName, "TODO"}); err != nil {
logrus.Fatal(err)
}
}
logrus.Infof(
"new recipe '%s' created in %s, happy hacking!\n",
recipe.Name, path.Join(config.APPS_DIR, recipe.Name),
recipeName, path.Join(config.APPS_DIR, recipeName),
)
return nil