diff --git a/TODO.md b/TODO.md index 6f998fa0..de9d7a7a 100644 --- a/TODO.md +++ b/TODO.md @@ -31,7 +31,7 @@ Disclaimer!: List is WIP - [ ] `volume` - [ ] `abra recipe` - [x] `ls` - - [ ] `create` (XXX: in progress) + - [x] `create` - [ ] `release` - [x] `versions` - [ ] `abra upgrade` diff --git a/cli/recipe.go b/cli/recipe.go index f7b664d5..7ca5e322 100644 --- a/cli/recipe.go +++ b/cli/recipe.go @@ -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 },