refactor(recipe): move SampleEnv method to new struct

This commit is contained in:
p4u1 2024-07-08 11:02:43 +02:00
parent f268e5893b
commit 73e9b818b4
3 changed files with 19 additions and 10 deletions

View File

@ -132,7 +132,7 @@ var appNewCommand = cli.Command{
var secrets AppSecrets
var secretTable *jsontable.JSONTable
if internal.Secrets {
sampleEnv, err := recipe.SampleEnv()
sampleEnv, err := r.SampleEnv()
if err != nil {
log.Fatal(err)
}

18
pkg/recipe/files.go Normal file
View File

@ -0,0 +1,18 @@
package recipe
import (
"fmt"
"path"
"coopcloud.tech/abra/pkg/config"
"coopcloud.tech/abra/pkg/envfile"
)
func (r Recipe2) SampleEnv() (map[string]string, error) {
envSamplePath := path.Join(config.RECIPES_DIR, r.Name, ".env.sample")
sampleEnv, err := envfile.ReadEnv(envSamplePath)
if err != nil {
return sampleEnv, fmt.Errorf("unable to discover .env.sample for %s", r.Name)
}
return sampleEnv, nil
}

View File

@ -238,15 +238,6 @@ func Get(recipeName string, offline bool) (Recipe, error) {
}, nil
}
func (r Recipe) SampleEnv() (map[string]string, error) {
envSamplePath := path.Join(config.RECIPES_DIR, r.Name, ".env.sample")
sampleEnv, err := envfile.ReadEnv(envSamplePath)
if err != nil {
return sampleEnv, fmt.Errorf("unable to discover .env.sample for %s", r.Name)
}
return sampleEnv, nil
}
func Get2(name string) Recipe2 {
return Recipe2{
Name: name,