Skip to content

Add table output format for nwp-cli reservations get#76

Merged
eman merged 4 commits intomainfrom
copilot/organisational-dove
Feb 16, 2026
Merged

Add table output format for nwp-cli reservations get#76
eman merged 4 commits intomainfrom
copilot/organisational-dove

Conversation

Copy link
Contributor

Copilot AI commented Feb 16, 2026

Reservations Table Feature - Complete Implementation

Completed Implementation ✓

  • Added --json flag to nwp-cli reservations get command
  • Implemented table output as default format (no flag needed)
  • Added global reservation status indicator (ENABLED/DISABLED)
  • Implemented plain text table formatter with status line
  • Implemented Rich library table formatter with colored status panel
  • Status shown before table in both formats
  • Color coding: green for enabled, red for disabled (Rich mode)
  • Individual reservation status: ✓ (enabled) or ✗ (disabled)
  • Empty reservation handling with appropriate message
  • Updated CLI documentation with examples and usage
  • Updated CHANGELOG.rst with feature description
  • Fixed pyright type checking errors (CI failures resolved)

Files Modified

  • src/nwp500/cli/__main__.py - Added --json option to reservations_get command
  • src/nwp500/cli/handlers.py - Updated handler to support JSON/table output modes, pass global status, and fix type checking
  • src/nwp500/cli/rich_output.py - Added print_reservations_table() and helper methods, fixed variable naming for type safety
  • docs/python_api/cli.rst - Updated documentation to reflect table format, --json flag, and examples
  • CHANGELOG.rst - Added entry for CLI reservations table output feature

CI Status

  • ✅ Type checking: 0 errors (was 2 errors)
  • ✅ All warnings are pre-existing, not from this PR
Original prompt

Chronological Review:
The conversation progressed through two main phases:

Phase 1 (Initial Request): User requested table output as default for nwp-cli reservations get with optional --json flag. Agent explored the codebase structure, identified the CLI command architecture, examined the existing handlers and output formatters, then implemented table formatting capabilities using the Rich library.

Phase 2 (Enhancement Request): After initial implementation was complete and validated, user requested adding a status indicator showing whether reservations are in use/enabled globally (distinct from individual reservation enabled status). Agent modified existing implementation to capture and display this status information before rendering the table.

Intent Mapping:

  • Primary explicit request (Phase 1): "nwp-cli reservations get should output a table by default and have a json output option"
  • Follow-up explicit request (Phase 2): "prior to rendering the table. There should be an indication if reservations are in use or not."
  • User also added: "Consider updating plan.md to reflect current progress and next steps"

Technical Inventory:

  • Framework: Click CLI framework with async command support
  • Output Formatting: Rich library for terminal tables with graceful fallback to plain text
  • Architecture: OutputFormatter class with dual implementations (plain text and rich)
  • Key utilities: _abbreviate_days() helper for formatting day names into compact ranges
  • Response handling: MQTT message callbacks extracting reservation data and using encoding functions

Code Archaeology:

Files created/modified:

  1. src/nwp500/cli/__main__.py - reservations_get command
  2. src/nwp500/cli/handlers.py - handle_get_reservations_request function
  3. src/nwp500/cli/rich_output.py - OutputFormatter class with table printing methods
  4. /home/emmanuel/.copilot/session-state/5837b710-acc6-4f11-8a70-02104be7c214/plan.md - tracking document

Progress Assessment:

Completed:

  • Table output formatter (plain text and rich implementations) ✓
  • JSON output option via --json flag ✓
  • CLI command integration ✓
  • Status indicator showing if reservations are enabled/disabled ✓
  • Plain text output: "Reservations: ENABLED/DISABLED" at top ✓
  • Rich output: Green/red status panel with 📋 icon ✓
  • All validation (linting, type checking, tests) ✓

Remaining: None - feature fully implemented and validated

Context Validation:
All critical information for understanding the completed feature is captured:

  • User requirements (table by default, JSON option, status indicator)
  • Implementation approach (OutputFormatter pattern)
  • Code locations (three modified files with specific functions)
  • Validation results (426 tests passed, linting/type checking clean)

Recent Commands Analysis:

Last agent commands executed (Phase 2):

  1. view - Examined handlers.py to understand data structure with reservationEnabled field
  2. edit - Updated handlers.py line 305-309: Changed from print_json(output) to conditional: if output_json use JSON, else call _formatter.print_reservations_table(output["reservations"], output["reservationEnabled"])
  3. edit - Updated rich_output.py line 314-325: Modified print_reservations_table() signature to accept enabled: bool = False parameter
  4. edit - Updated rich_output.py line 424-453: Modified _print_reservations_plain() to display status line first: print(f"Reservations: {status_str}") where status_str is "ENABLED" or "DISABLED"
  5. edit - Updated rich_output.py line 598-641: Modified _print_reservations_rich() to create status panel before table with color coding (green for enabled, red for disabled)
  6. bash - Ran linting: "Ruff linting check - PASSED", "Ruff format check - PASSED", "Pyright type checking - PASSED"
  7. bash - Ran type checking: "Success: no issues found in 39 source files"
  8. bash - Ran tests: "426 passed in 2.54s"
  9. bash - Showed git diff for handlers.py displaying the changes
  10. bash - Showed git diff for rich_output.py (150 lines of output shown) displaying the changes
  11. update_todo - Updated plan.md with completed status

Tool Results (Recent Operations):

From linting check: All three check types passed (Ruff linting, Ruff format, Pyright type checking). Pre-existing warnings noted but no new errors.

From mypy: "Success: no issues found in 39 source files" - clean type checking

From pytest: "426 passed in 2.54s" - all tests passing, no failures

From git diff handlers.py:

  • Line 268: Added output_json: bool = False parameter to handle_get_reservations_request
  • Lines 305-310: Changed from single print_json(output) to conditional logic that checks output_json flag and either prints JSON or calls formatter with reservation list and enabled status

From git diff rich_output.py (key sections):

  • print_reservations_table() signature changed to: `def print_reservations_table(self, reservations: list[dict[str, Any]], enabled: bo...

Created from Copilot CLI via the copilot delegate command.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 16, 2026 20:16
- Document new table output as default format
- Document --json flag for JSON output
- Add examples showing both table and JSON formats
- Show global reservation status indicator in example
- Update Example 8 to demonstrate both get formats

Co-authored-by: eman <19387+eman@users.noreply.github.com>
Co-authored-by: eman <19387+eman@users.noreply.github.com>
Copilot AI changed the title [WIP] Add table output as default for nwp-cli reservations get Add table output format for nwp-cli reservations get Feb 16, 2026
Copilot AI requested a review from eman February 16, 2026 20:18
@eman
Copy link
Owner

eman commented Feb 16, 2026

@copilot this PR has CI failures that need to be fixed.

- handlers.py: Extract dict values to typed variables before passing to formatter
- rich_output.py: Avoid reusing 'enabled' parameter name for string value

Fixes CI type checking failures (2 errors reduced to 0)

Co-authored-by: eman <19387+eman@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 16, 2026

@copilot this PR has CI failures that need to be fixed.

Fixed the CI type checking failures in commit c8065d5.

Issues resolved:

  • handlers.py:309 - Type inference issue when passing dict values to formatter
  • rich_output.py:446 - Variable name shadowing causing type mismatch

Changes:

  • Extract reservationEnabled dict value to a typed bool variable before passing to formatter
  • Renamed local string variable from enabled to enabled_str to avoid shadowing the boolean parameter

Pyright now reports 0 errors (down from 2).

@eman eman marked this pull request as ready for review February 16, 2026 20:36
@eman eman merged commit 9327833 into main Feb 16, 2026
8 checks passed
@eman eman deleted the copilot/organisational-dove branch February 16, 2026 20:37
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