feat: improved recipe creation
This commit is contained in:
parent
4283f130a2
commit
decfe095fe
|
@ -47,6 +47,7 @@ var ForceFlag = &cli.BoolFlag{
|
||||||
Name: "force",
|
Name: "force",
|
||||||
Value: false,
|
Value: false,
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"f"},
|
||||||
|
Usage: "Perform action without further prompt. Use with care!",
|
||||||
Destination: &Force,
|
Destination: &Force,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,20 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"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{
|
var recipeNewCommand = &cli.Command{
|
||||||
Name: "new",
|
Name: "new",
|
||||||
Usage: "Create a new recipe",
|
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
|
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
|
which Abra uses to inject values into the generated recipe folder (e.g. name of
|
||||||
recipe and domain in the sample environment config).
|
recipe and domain in the sample environment config).
|
||||||
|
|
||||||
The new example repository is cloned to ~/.abra/apps/<recipe>.
|
|
||||||
`,
|
`,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
recipeName := c.Args().First()
|
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 {
|
if err := os.RemoveAll(gitRepo); err != nil {
|
||||||
logrus.Fatal(err)
|
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{
|
toParse := []string{
|
||||||
path.Join(config.RECIPES_DIR, recipeName, "README.md"),
|
path.Join(config.RECIPES_DIR, recipeName, "README.md"),
|
||||||
path.Join(config.RECIPES_DIR, recipeName, ".env.sample"),
|
path.Join(config.RECIPES_DIR, recipeName, ".env.sample"),
|
||||||
path.Join(config.RECIPES_DIR, recipeName, ".drone.yml"),
|
|
||||||
}
|
}
|
||||||
for _, path := range toParse {
|
for _, path := range toParse {
|
||||||
file, err := os.OpenFile(path, os.O_RDWR, 0664)
|
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)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ask for description and probably other things so that the
|
if err := tpl.Execute(file, meta); err != nil {
|
||||||
// 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 {
|
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,11 +94,39 @@ The new example repository is cloned to ~/.abra/apps/<recipe>.
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof(
|
fmt.Print(fmt.Sprintf(`
|
||||||
"new recipe %s created in %s, happy hacking!\n",
|
Your new %s recipe has been created in %s.
|
||||||
recipeName, path.Join(config.RECIPES_DIR, recipeName),
|
|
||||||
)
|
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
|
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