Skip to content

Commit df64898

Browse files
refactor(cli): use ResultReporter in system handlers
1 parent df14f66 commit df64898

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

hatch/cli/cli_system.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434

3535
from hatch_validator import HatchPackageValidator
3636

37-
from hatch.cli.cli_utils import EXIT_SUCCESS, EXIT_ERROR
37+
from hatch.cli.cli_utils import (
38+
EXIT_SUCCESS,
39+
EXIT_ERROR,
40+
ResultReporter,
41+
ConsequenceType,
42+
)
3843
from hatch.template_generator import create_package_template
3944

4045

@@ -52,17 +57,26 @@ def handle_create(args: Namespace) -> int:
5257
"""
5358
target_dir = Path(args.dir).resolve()
5459
description = getattr(args, "description", "")
60+
dry_run = getattr(args, "dry_run", False)
5561

62+
# Create reporter for unified output
63+
reporter = ResultReporter("hatch create", dry_run=dry_run)
64+
reporter.add(ConsequenceType.CREATE, f"Package '{args.name}' at {target_dir}")
65+
66+
if dry_run:
67+
reporter.report_result()
68+
return EXIT_SUCCESS
69+
5670
try:
5771
package_dir = create_package_template(
5872
target_dir=target_dir,
5973
package_name=args.name,
6074
description=description,
6175
)
62-
print(f"Package template created at: {package_dir}")
76+
reporter.report_result()
6377
return EXIT_SUCCESS
6478
except Exception as e:
65-
print(f"Failed to create package template: {e}")
79+
print(f"[ERROR] Failed to create package template: {e}")
6680
return EXIT_ERROR
6781

6882

@@ -82,6 +96,9 @@ def handle_validate(args: Namespace) -> int:
8296
env_manager: HatchEnvironmentManager = args.env_manager
8397
package_path = Path(args.package_dir).resolve()
8498

99+
# Create reporter for unified output
100+
reporter = ResultReporter("hatch validate", dry_run=False)
101+
85102
# Create validator with registry data from environment manager
86103
validator = HatchPackageValidator(
87104
version="latest",
@@ -93,10 +110,11 @@ def handle_validate(args: Namespace) -> int:
93110
is_valid, validation_results = validator.validate_package(package_path)
94111

95112
if is_valid:
96-
print(f"Package validation SUCCESSFUL: {package_path}")
113+
reporter.add(ConsequenceType.VALIDATE, f"Package '{package_path.name}'")
114+
reporter.report_result()
97115
return EXIT_SUCCESS
98116
else:
99-
print(f"Package validation FAILED: {package_path}")
117+
print(f"[ERROR] Package validation FAILED: {package_path}")
100118

101119
# Print detailed validation results if available
102120
if validation_results and isinstance(validation_results, dict):

0 commit comments

Comments
 (0)