openhue-cli icon indicating copy to clipboard operation
openhue-cli copied to clipboard

add terminal display to ease parsing for command line

Open pantelm opened this issue 2 months ago • 2 comments

Print without header and blank line to ease parsing with cli tools

Summary by CodeRabbit

  • New Features
    • Added --terminal (short -c) flag to the get command, providing a terminal-friendly output format option alongside the existing JSON format for displaying light information.

pantelm avatar Nov 16 '25 09:11 pantelm

Walkthrough

The changes introduce a --terminal flag to the get command for alternative output formatting. A new generic utility function PrintTerminal is added to enable terminal-based output, and the light command implementation conditionally routes non-JSON output through this terminal formatter when the flag is active.

Changes

Cohort / File(s) Summary
Command Configuration
cmd/get/get.go
Added Terminal bool field to CmdGetOptions struct and wired a new --terminal (-c) command-line flag to control terminal-based output formatting.
Command Implementation
cmd/get/get_light.go
Added conditional logic to route non-JSON output to PrintLight terminal formatter when Terminal flag is set, replacing the previous unconditional table format behavior for this code path.
Output Utilities
util/utils.go
Added new generic function PrintTerminal[T any] that accepts an I/O stream, a table slice, and a line formatter function to print each element without table formatting.

Sequence Diagram

sequenceDiagram
    participant User
    participant get_light
    participant utils
    participant IO
    
    User->>get_light: RunGetLightCmd(--terminal)
    
    rect rgb(200, 220, 255)
    Note over get_light: JSON format check
    get_light->>get_light: o.JSON == true?
    end
    
    alt JSON output
        get_light->>IO: PrintJSON()
    else Terminal output (NEW)
        rect rgb(220, 255, 220)
        get_light->>utils: PrintTerminal()
        utils->>IO: Println() per light
        end
    else Table output (default)
        get_light->>IO: PrintTable()
    end

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Focus on the conditional routing logic in get_light.go to ensure the Terminal flag correctly gates the formatter selection
  • Verify the new PrintTerminal generic function handles edge cases (empty slices, nil streams)
  • Confirm the --terminal flag registration in get.go uses the correct option name and doesn't conflict with existing flags

Poem

🐰 A terminal flag hops into view,
New formatting paths for a colorful brew,
PrintTerminal springs with generic delight,
Output now routes to the terminal light! ✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'add terminal display to ease parsing for command line' accurately reflects the main change: adding a new terminal display mode with a new --terminal flag and PrintTerminal utility function to enable simpler CLI output parsing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 16 '25 09:11 coderabbitai[bot]

Salut @pantelm - I was wondering if using the --json flag + jq would help you solve this problem?

As example, I usually use:

openhue get lights --json | jq '.[].Name'

to list all my lights

thibauult avatar Nov 17 '25 14:11 thibauult