forked from coop-cloud/abra
feat: improved recipe creation
This commit is contained in:
parent
4283f130a2
commit
decfe095fe
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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/<recipe>.
|
||||
`,
|
||||
Action: func(c *cli.Context) error {
|
||||
recipeName := c.Args().First()
|
||||
|
@ -53,12 +65,13 @@ The new example repository is cloned to ~/.abra/apps/<recipe>.
|
|||
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/<recipe>.
|
|||
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/<recipe>.
|
|||
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: "",
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue