Skip to content

Commit 2262745

Browse files
committed
fix: use io writer in recipe generator
meteor new command allows user to generate recipe, although the functionality is fine, I want use this method to generate recipe outside of meteor as well. If this is being called programmatically printing it to hard coded stdout blocked me to take the output as a string. Signed-off-by: Kush Sharma <[email protected]>
1 parent 2309f9f commit 2262745

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

cmd/new.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"errors"
5+
"os"
56
"strings"
67

78
"github.com/AlecAivazis/survey/v2"
@@ -95,7 +96,7 @@ func NewRecipeCmd() *cobra.Command {
9596
Scope: scope,
9697
Sinks: sinkList,
9798
Processors: procList,
98-
})
99+
}, os.Stdout)
99100
},
100101
}
101102

generator/recipe.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package generator
22

33
import (
44
"embed"
5-
"os"
5+
"io"
66
"strings"
77
"text/template"
88

@@ -42,7 +42,7 @@ type RecipeParams struct {
4242
}
4343

4444
// Recipe checks if the recipe is valid and returns a Template
45-
func Recipe(p RecipeParams) error {
45+
func Recipe(p RecipeParams, writer io.Writer) error {
4646
tem := templateData{
4747
Name: p.Name,
4848
Version: recipeVersions[len(recipeVersions)-1],
@@ -83,7 +83,7 @@ func Recipe(p RecipeParams) error {
8383
tmpl := template.Must(
8484
template.New("recipe.yaml").Funcs(templateFuncs).ParseFS(file, "*"),
8585
)
86-
if err := tmpl.Execute(os.Stdout, tem); err != nil {
86+
if err := tmpl.Execute(writer, tem); err != nil {
8787
return errors.Wrap(err, "failed to execute template")
8888
}
8989
return nil

0 commit comments

Comments
 (0)