refactor(recipe): remove direct usage of config.RECIPE_DIR

This commit is contained in:
2024-07-08 13:38:29 +02:00
parent f14d49cc64
commit 87ecc05962
17 changed files with 82 additions and 117 deletions

View File

@ -62,17 +62,16 @@ recipe and domain in the sample environment config).
internal.ShowSubcommandHelpAndError(c, errors.New("no recipe name provided"))
}
directory := path.Join(config.RECIPES_DIR, recipeName)
if _, err := os.Stat(directory); !os.IsNotExist(err) {
log.Fatalf("%s recipe directory already exists?", directory)
if _, err := os.Stat(r.Dir); !os.IsNotExist(err) {
log.Fatalf("%s recipe directory already exists?", r.Dir)
}
url := fmt.Sprintf("%s/example.git", config.REPOS_BASE_URL)
if err := git.Clone(directory, url); err != nil {
if err := git.Clone(r.Dir, url); err != nil {
log.Fatal(err)
}
gitRepo := path.Join(config.RECIPES_DIR, recipeName, ".git")
gitRepo := path.Join(r.Dir, ".git")
if err := os.RemoveAll(gitRepo); err != nil {
log.Fatal(err)
}
@ -91,14 +90,13 @@ recipe and domain in the sample environment config).
log.Fatal(err)
}
if err := os.WriteFile(path, templated.Bytes(), 0644); err != nil {
if err := os.WriteFile(path, templated.Bytes(), 0o644); err != nil {
log.Fatal(err)
}
}
newGitRepo := path.Join(config.RECIPES_DIR, recipeName)
if err := git.Init(newGitRepo, true, internal.GitName, internal.GitEmail); err != nil {
if err := git.Init(r.Dir, true, internal.GitName, internal.GitEmail); err != nil {
log.Fatal(err)
}
@ -117,7 +115,7 @@ See "abra recipe -h" for additional recipe maintainer commands.
Happy Hacking!
`, recipeName, path.Join(config.RECIPES_DIR, recipeName), recipeName))
`, recipeName, path.Join(r.Dir), recipeName))
return nil
},