Skip to content

Commit

Permalink
feat: include a warning about generated files when generating files 💪 (
Browse files Browse the repository at this point in the history
…#33)

I recently landed myself in an `id_gen.go` file using IDE's Go To Definition and started making updates, not noticing that it was a generated file.

This preamble would probably not help me because the file was long but perhaps it will help someone else. 🤷‍♂️

Co-authored-by: Tomas Zahradnicek <[email protected]>
  • Loading branch information
robertrossmann and Fazt01 committed Aug 16, 2024
1 parent f47a1fb commit 23eea15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ How to release a new version:
### Added
- Use `debug.ReadBuildInfo` to get correct version.
- Print to stderr on error.
- `gen_id` now includes a comment at the top of the generated file to warn developers that the file is, in fact, generated.

### Removed
- `openapi compose`, `repo init`, `repo template` commands.
Expand Down
5 changes: 5 additions & 0 deletions cmd/tea/gen_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
)

var (
outputPreamble = "// Code generated by tea. DO NOT EDIT.\n\n"
// genIDCmd represents the id command
genIDCmd = &cobra.Command{
Use: "id",
Expand Down Expand Up @@ -134,6 +135,10 @@ 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

0 comments on commit 23eea15

Please sign in to comment.