Skip to content

Fix -comment flag handling for multi-line values#8

Open
stevendpclark wants to merge 1 commit into
masterfrom
stevendpclark_fix_comment_arg_newline
Open

Fix -comment flag handling for multi-line values#8
stevendpclark wants to merge 1 commit into
masterfrom
stevendpclark_fix_comment_arg_newline

Conversation

@stevendpclark

Copy link
Copy Markdown
Owner

Summary

  • When the -comment argument contains newline characters, the generated file now emits one // -prefixed line per segment instead of embedding the raw newline inside a single comment line (which produces invalid Go)
  • The same newline-in-args edge case is sanitized in the DO NOT EDIT header line by collapsing embedded newlines to spaces
  • Replaces deprecated ioutil.TempFile with os.CreateTemp (deprecated since Go 1.16)

Root cause

g.Printf("// %s\n", comments.String()) emitted the comment as a single Printf call. If the string contained \n, the output would be:

// line one
line two // ← not a comment — syntax error

Fix

Split the comment string on \n and emit each segment as its own // … line.

Test plan

  • TestCommentWithNewline — end-to-end test: builds the enumer binary, generates a file with -comment "line one\nline two", asserts both comment lines appear in the output, and verifies the generated file compiles cleanly

Summary

- When the -comment argument contains newline characters, the generated file now emits one // -prefixed line per segment instead of embedding the raw newline
inside a single comment line (which produces invalid Go)
- The same newline-in-args edge case is sanitized in the DO NOT EDIT header line by collapsing embedded newlines to spaces
- Replaces deprecated ioutil.TempFile with os.CreateTemp (deprecated since Go 1.16)

Root cause

g.Printf("// %s\n", comments.String()) emitted the comment as a single Printf call. If the string contained \n, the output would be:

// line one
line two   // ← not a comment — syntax error

Fix

Split the comment string on \n and emit each segment as its own // … line.

Test plan

- TestCommentWithNewline — end-to-end test: builds the enumer binary, generates a file with -comment "line one\nline two", asserts both comment lines appear in
the output, and verifies the generated file compiles cleanly
@stevendpclark stevendpclark requested review from ncabatoff and victorr May 7, 2026 23:00
@stevendpclark stevendpclark self-assigned this May 7, 2026
@stevendpclark stevendpclark added the bug Something isn't working label May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant