forked from coop-cloud/abra
parent
c76bd25c1d
commit
7022f42711
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user