Skip to content

Commit 28ec610

Browse files
feat(cli): add format_warning utility
1 parent 4d0ab73 commit 28ec610

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

hatch/cli/cli_utils.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,37 @@ def format_info(message: str) -> None:
851851
print(f"[INFO] {message}")
852852

853853

854+
def format_warning(message: str, suggestion: str = None) -> None:
855+
"""Print formatted warning message with color.
856+
857+
Prints message with [WARNING] prefix in bright yellow color.
858+
Used for non-fatal warnings that don't prevent operation completion.
859+
860+
Reference: R13-A §A.5 P3 (13-error_message_formatting_appendix_a_v0.md)
861+
862+
Args:
863+
message: Warning message to display
864+
suggestion: Optional suggestion for resolution
865+
866+
Output format:
867+
[WARNING] <message>
868+
Suggestion: <suggestion> (if provided)
869+
870+
Example:
871+
>>> from hatch.cli.cli_utils import format_warning
872+
>>> format_warning("Invalid header format 'foo'", suggestion="Expected KEY=VALUE")
873+
[WARNING] Invalid header format 'foo'
874+
Suggestion: Expected KEY=VALUE
875+
"""
876+
if _colors_enabled():
877+
print(f"{Color.YELLOW.value}[WARNING]{Color.RESET.value} {message}")
878+
else:
879+
print(f"[WARNING] {message}")
880+
881+
if suggestion:
882+
print(f" Suggestion: {suggestion}")
883+
884+
854885
# =============================================================================
855886
# TableFormatter Infrastructure for List Commands
856887
# =============================================================================

0 commit comments

Comments
 (0)