feat: finish recipe create command

This commit is contained in:
decentral1se 2021-07-25 19:28:29 +02:00
parent 359b07b562
commit 1f550c2470
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 35 additions and 10 deletions

View File

@ -31,7 +31,7 @@ Disclaimer!: List is WIP
- [ ] `volume`
- [ ] `abra recipe`
- [x] `ls`
- [ ] `create` (XXX: in progress)
- [x] `create`
- [ ] `release`
- [x] `versions`
- [ ] `abra upgrade`

View File

@ -8,6 +8,7 @@ import (
"os"
"path"
"sort"
"text/template"
"time"
"coopcloud.tech/abra/config"
@ -236,22 +237,46 @@ var recipeCreateCommand = &cli.Command{
return nil
}
toRemove := []string{
path.Join(config.APPS_DIR, recipe, ".git"),
path.Join(config.APPS_DIR, recipe, ".gitea"),
gitRepo := path.Join(config.APPS_DIR, recipe, ".git")
if err := os.RemoveAll(gitRepo); err != nil {
logrus.Fatal(err)
return nil
}
toParse := []string{
path.Join(config.APPS_DIR, recipe, "README.md"),
path.Join(config.APPS_DIR, recipe, ".env.sample"),
path.Join(config.APPS_DIR, recipe, ".drone.yml"),
}
for _, path := range toRemove {
if err := os.RemoveAll(path); err != nil {
for _, path := range toParse {
file, err := os.OpenFile(path, os.O_RDWR, 0755)
if err != nil {
logrus.Fatal(err)
return nil
}
tpl, err := template.ParseFiles(path)
if err != nil {
logrus.Fatal(err)
return nil
}
// 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
}{recipe, "TODO"}); err != nil {
logrus.Fatal(err)
return nil
}
}
// TODO: implement final %s logic on new repo files
// sed -i "s/\${REPO_NAME}/$recipe/g" README.md
// sed -i "s/\${REPO_NAME_TITLE}/$recipe/g" README.md
// sed -i "s/\${REPO_NAME_KEBAB}/$recipe_kebab/g" .env.sample
fmt.Printf(
"New recipe '%s' created in %s, happy hacking!",
recipe, path.Join(config.APPS_DIR, recipe),
)
return nil
},