Skip to content

Commit

Permalink
fix: output preamble in generated file
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Kocman committed Oct 14, 2024
1 parent 583a2f5 commit abcdef8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions cmd/tea/gen_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ import (
"github.com/spf13/cobra"
)

var (
const (
outputPreamble = "// Code generated by tea. DO NOT EDIT.\n\n"
)

var (
// genIDCmd represents the id command
genIDCmd = &cobra.Command{
Use: "id",
Expand Down Expand Up @@ -135,10 +138,6 @@ func (i IDs) generate() ([]byte, error) {
var genData []byte
var err error

if _, err = output.WriteString(outputPreamble); err != nil {
return nil, fmt.Errorf("writing output preamble: %w", err)
}

for typ := range i {
//nolint:gocritic,exhaustive
switch typ {
Expand Down Expand Up @@ -361,6 +360,9 @@ func runGenerateIDs(sourceFilePath, outputFilePath string) error {
}
}()

if _, err = outputFile.Write([]byte(outputPreamble)); err != nil {
return cmderrors.NewCommandError(fmt.Errorf("writing output preamble: %w", err), cmderrors.CodeIO)
}
if _, err = outputFile.Write(ids.generateHeader()); err != nil {
return cmderrors.NewCommandError(fmt.Errorf("writing output header: %w", err), cmderrors.CodeIO)
}
Expand Down

0 comments on commit abcdef8

Please sign in to comment.