feat: add --json support for history command#55
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a --json flag to eko history to emit snapshot history as a JSON array for programmatic consumption, while keeping the default human-readable output intact.
Changes:
- Added
--jsonCobra flag tohistoryand JSON marshaling of snapshot records. - Improved DB query handling in
history(captures query/scan errors; ensures[]output for empty history). - Added unit test coverage validating that
eko history --jsonreturns valid JSON with expected fields.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cmd/history.go | Adds --json output mode and structures history records for JSON serialization. |
| cmd/commands_test.go | Adds a unit test for JSON history output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+33
to
53
| entries := []historyEntry{} | ||
| for rows.Next() { | ||
| var id, created string | ||
| rows.Scan(&id, &created) | ||
| fmt.Println(id, created) | ||
| var entry historyEntry | ||
| if err := rows.Scan(&entry.ID, &entry.CreatedAt); err != nil { | ||
| panic(err) | ||
| } | ||
| entries = append(entries, entry) | ||
| } | ||
|
|
||
| if jsonOutput { | ||
| data, err := json.Marshal(entries) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| fmt.Println(string(data)) | ||
| return | ||
| } | ||
|
|
||
| for _, entry := range entries { | ||
| fmt.Println(entry.ID, entry.CreatedAt) | ||
| } |
Comment on lines
+155
to
+160
| defer func() { | ||
| jsonOutput = false | ||
| if err := historyCmd.Flags().Set("json", "false"); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| }() |
kavix
approved these changes
Jul 5, 2026
Owner
|
@hfl0506 Thank you for your contribution! We appreciate the time and effort you put into improving the project. We look forward to your future contributions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
--jsonflag toeko historyso snapshot history can be printed as a JSON array for programmatic parsing.The default
eko historyoutput remains unchanged.Related Issues
Resolve #49
Type of Change
Technical Details & Architecture Notes
--json, to the history command.encoding/json.[]when there are no history entries.How Has This Been Tested?
go test -v ./...results: all tests passed.go vet ./...results: no issues reported.eko history --json.Testing Steps
Testing Result
Checklist
gofmtandgo vet)README.mdandCONTRIBUTING.md)