feat: finish recipe create command
This commit is contained in:
		@ -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
 | 
			
		||||
	},
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user