feat: finish recipe create command
This commit is contained in:
parent
359b07b562
commit
1f550c2470
2
TODO.md
2
TODO.md
|
@ -31,7 +31,7 @@ Disclaimer!: List is WIP
|
||||||
- [ ] `volume`
|
- [ ] `volume`
|
||||||
- [ ] `abra recipe`
|
- [ ] `abra recipe`
|
||||||
- [x] `ls`
|
- [x] `ls`
|
||||||
- [ ] `create` (XXX: in progress)
|
- [x] `create`
|
||||||
- [ ] `release`
|
- [ ] `release`
|
||||||
- [x] `versions`
|
- [x] `versions`
|
||||||
- [ ] `abra upgrade`
|
- [ ] `abra upgrade`
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"sort"
|
"sort"
|
||||||
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"coopcloud.tech/abra/config"
|
"coopcloud.tech/abra/config"
|
||||||
|
@ -236,22 +237,46 @@ var recipeCreateCommand = &cli.Command{
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
toRemove := []string{
|
gitRepo := path.Join(config.APPS_DIR, recipe, ".git")
|
||||||
path.Join(config.APPS_DIR, recipe, ".git"),
|
if err := os.RemoveAll(gitRepo); err != nil {
|
||||||
path.Join(config.APPS_DIR, recipe, ".gitea"),
|
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"),
|
path.Join(config.APPS_DIR, recipe, ".drone.yml"),
|
||||||
}
|
}
|
||||||
for _, path := range toRemove {
|
for _, path := range toParse {
|
||||||
if err := os.RemoveAll(path); err != nil {
|
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)
|
logrus.Fatal(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement final %s logic on new repo files
|
fmt.Printf(
|
||||||
// sed -i "s/\${REPO_NAME}/$recipe/g" README.md
|
"New recipe '%s' created in %s, happy hacking!",
|
||||||
// sed -i "s/\${REPO_NAME_TITLE}/$recipe/g" README.md
|
recipe, path.Join(config.APPS_DIR, recipe),
|
||||||
// sed -i "s/\${REPO_NAME_KEBAB}/$recipe_kebab/g" .env.sample
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue