-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add --plain output and fix auth stderr #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/initial-template
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -64,6 +64,30 @@ func WriteJSON(w io.Writer, v any) error { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // WritePlain writes tab-separated values to the writer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func WritePlain(w io.Writer, headers []string, rows [][]string) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| replacer := strings.NewReplacer("\t", " ", "\n", " ", "\r", "") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if len(headers) > 0 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if _, err := fmt.Fprintln(w, strings.Join(headers, "\t")); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("write plain headers: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, row := range rows { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cleaned := make([]string, len(row)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i, cell := range row { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cleaned[i] = replacer.Replace(cell) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if _, err := fmt.Fprintln(w, strings.Join(cleaned, "\t")); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return fmt.Errorf("write plain row: %w", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return nil | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
68
to
88
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write errors silently discarded
Suggested change
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! Prompt To Fix With AIThis is a comment left during a code review.
Path: internal/outfmt/outfmt.go
Line: 68:77
Comment:
**Write errors silently discarded**
`WritePlain` returns `error` but never returns a non-nil one — `fmt.Fprintln` write errors are silently ignored. This is minor since stdout write failures are typically unrecoverable, but for consistency with `WriteJSON` (which wraps encode errors), consider checking at least one write:
```suggestion
// WritePlain writes tab-separated values to the writer.
func WritePlain(w io.Writer, headers []string, rows [][]string) error {
if len(headers) > 0 {
if _, err := fmt.Fprintln(w, strings.Join(headers, "\t")); err != nil {
return fmt.Errorf("write plain headers: %w", err)
}
}
for _, row := range rows {
if _, err := fmt.Fprintln(w, strings.Join(row, "\t")); err != nil {
return fmt.Errorf("write plain row: %w", err)
}
}
return nil
}
```
<sub>Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!</sub>
How can I resolve this? If you propose a fix, please make it concise.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed — WritePlain now propagates fmt.Fprintln errors. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func KeyValuePayload(key string, value any) map[string]any { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return map[string]any{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "key": key, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TSV output breaks on embedded tabs/newlines
WritePlainjoins cell values with\tand writes rows withFprintln, but does not sanitize the values. API responses for fields likeAnswerandSummarycan contain tab and newline characters, which will corrupt the TSV structure — a newline inside a cell will be interpreted as a row boundary, and a tab will be interpreted as a column boundary.Consider replacing or stripping
\tand\nfrom cell values before joining. For example:Prompt To Fix With AI
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — WritePlain now sanitizes tabs/newlines with strings.NewReplacer.