Skip to content

refactoring(cli): print_console#578

Merged
enyst merged 2 commits intomainfrom
vasco/concole_print
Mar 8, 2026
Merged

refactoring(cli): print_console#578
enyst merged 2 commits intomainfrom
vasco/concole_print

Conversation

@VascoSch92
Copy link
Contributor

@VascoSch92 VascoSch92 commented Mar 7, 2026

What: Extended console_print in auth/utils.py with an optional style keyword parameter that auto-wraps the message in
[{style}]...[/{style}] markup. Updated ~40 call sites across 6 files:

  • auth/utils.py, auth/login_command.py, auth/logout_command.py
  • auth/device_flow.py, auth/api_client.py
  • cloud/command.py, cloud/conversation.py

Why: The verbose f"[{OPENHANDS_THEME.X}]msg[/{OPENHANDS_THEME.X}]" pattern was repeated 40+ times — error-prone (easy to mismatch open/close tags) and noisy. Now callers just write console_print("msg", style=OPENHANDS_THEME.success).
The style parameter is backward-compatible so zero test changes were needed.

Note:
When I refactored cloud/command.py, I removed the local console = Console() instance and replaced all console.print(...) calls with console_print(...) (imported from auth/utils.py).

But the two tests in test_main.py were patching openhands_cli.cloud.command.console — an attribute that no longer existed in the module. So patch() raised AttributeError.

The fix was simply updating those two test mocks to patch openhands_cli.cloud.command.console_print instead, matching the new function the module actually uses.


🚀 Try this PR

uvx --python 3.12 git+https://github.com/OpenHands/OpenHands-CLI.git@vasco/concole_print

@VascoSch92 VascoSch92 requested a review from all-hands-bot March 7, 2026 09:32
@github-actions
Copy link
Contributor

github-actions bot commented Mar 7, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands_cli/auth
   api_client.py1322382%80, 97–102, 105, 107–110, 126, 173, 182, 197–198, 218, 222, 249, 302–304
   device_flow.py95297%111–112
   login_command.py50394%37, 79, 83
   logout_command.py250100% 
   utils.py34294%31, 90
openhands_cli/cloud
   command.py25772%22–23, 63, 65–68
   conversation.py64985%73, 97–102, 117, 130
TOTAL664093585% 

all-hands-bot

This comment was marked as outdated.

@VascoSch92 VascoSch92 requested a review from all-hands-bot March 7, 2026 09:57
Copy link
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

🟢 Good taste - This is solid engineering.

What this does right:

  • Solves a real, measurable problem (40+ instances of error-prone boilerplate)
  • Simple solution: 3-line function with optional parameter
  • Backward compatible: zero breaking changes
  • Applied consistently across the entire codebase
  • Eliminates special case handling at all call sites

The "Linus Test":

  1. Real problem? ✅ Yes - verbose, repetitive markup pattern that is error-prone
  2. Simpler way? ✅ This IS the simple way - optional wrapper parameter
  3. What breaks? ✅ Nothing - backward compatible design

Verdict: Clean refactoring that improves maintainability without adding complexity. The abstraction level is appropriate and the implementation is straightforward. This is the kind of pragmatic cleanup that makes codebases better.

Ship it. 🚀

@VascoSch92 VascoSch92 requested a review from malhotra5 March 7, 2026 10:00
@VascoSch92 VascoSch92 marked this pull request as ready for review March 7, 2026 10:00
Copy link
Collaborator

@all-hands-bot all-hands-bot left a comment

Choose a reason for hiding this comment

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

🟢 Good taste - This is solid engineering.

What this does right:

  • Solves a real, measurable problem (40+ instances of error-prone boilerplate)
  • Simple solution: 3-line function with optional parameter
  • Backward compatible: zero breaking changes
  • Applied consistently across the entire codebase
  • Eliminates special case handling at all call sites

The "Linus Test":

  1. Real problem? ✅ Yes - verbose, repetitive markup pattern that is error-prone
  2. Simpler way? ✅ This IS the simplest way - optional param wraps the message once
  3. What breaks? ✅ Nothing - backward compatible, tests confirm this

Key Insight:
Moving the markup wrapping from 40+ call sites into one function is textbook "good taste" - the new call sites have no special cases, just console_print("msg", style=THEME.success). Clean separation of message from styling.

Previous review comments about incomplete refactoring and missing tests have been addressed. The code is ready.

Approved

Copy link
Collaborator

@enyst enyst left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@enyst enyst merged commit 2ffe8fe into main Mar 8, 2026
14 checks passed
@enyst enyst deleted the vasco/concole_print branch March 8, 2026 03:57
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.

3 participants