Skip to content

Implement tabular and property-based CLI output formatting#11

Merged
berggren merged 2 commits intomainfrom
format-output
Apr 2, 2026
Merged

Implement tabular and property-based CLI output formatting#11
berggren merged 2 commits intomainfrom
format-output

Conversation

@berggren
Copy link
Copy Markdown
Contributor

@berggren berggren commented Apr 2, 2026

Summary

Refactored struct printing logic to support tabular views for collections and formatted property views for individual objects.

$ openrelik folder list
ID   DISPLAY NAME          UPDATED
329  foobar                about 11 minutes ago
325  ghahaha               about 3 hours ago
321  CLI Uploads (jbn)     about 3 hours ago
319  blahonga              about 3 hours ago
174  CLI test folder       about 6 days ago
135  CLI Uploads           about 13 days ago
122  Test CLI client       about 15 days ago
121  Test markdown         about 16 days ago
103  Test Root 1773230574  about 22 days ago
101  Root Folder           about 22 days ago
97   Test                  about 23 days ago
27   Old                   about 23 days ago
$ openrelik file info 1184
ID            1184
Created       2026-04-02T11:47:23Z
Updated       2026-04-02T11:47:23Z
Deleted       false
Display Name  2020JimmyWilson.E01
UUID          b6f96b3c18284591abfd08041eea82ee
Filename      2020JimmyWilson.E01
Size          295.5MB
Extension     E01
Magic Text    EWF/Expert Witness/EnCase image file format
Magic Mime    application/octet-stream
Type          file:generic
MD5           4193cc3bc7111ddf8be7a00677f2a2f4
SHA1          711b07ad5b8f7be3a7f4bdf84f274e02e57d2db5
SHA256        6c18f662744d55e2769d9510f6173f04dab668c42b67ef27b675d22e628b4ed5
User ID       1

Technical Details:

  • Property View Formatting: Added FprintPropertyView to display struct fields as vertical key-value pairs. This function maps Go field names to human-readable labels (e.g., HashMD5 to MD5) and filters out empty strings, nil pointers, and nested structures to reduce noise in the CLI output.
  • Tabular Output: Introduced FprintTable to render slices of structs as formatted tables. It dynamically selects columns based on field availability, prioritizing identifiers and metadata like ID, DisplayName, Size, and Status.
  • Relative Time Formatting: Added FormatTimeAgo to convert time.Time values into human-readable relative strings, such as "about 2 hours ago," for better temporal context in command outputs.
  • Logic Refactoring: Updated FprintStruct to act as a router, delegating to FprintTable for slices and FprintPropertyView for single items, replacing the previous hyphen-separated list format.
  • Test Coverage: Expanded format_test.go with test cases for table rendering, relative time calculations, and the updated property view logic.

@berggren berggren requested a review from hacktobeer April 2, 2026 15:25
Copy link
Copy Markdown

@hacktobeer hacktobeer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit for follow up PR. LGTM


// Custom label mapping for a cleaner UI
switch field.Name {
case "ID":
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this a lookup table defined at the top instead of a case switch in a later PR. Cleaner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I will add it.

@berggren berggren merged commit 9aca3c7 into main Apr 2, 2026
3 checks passed
@berggren berggren deleted the format-output branch April 2, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants