3333from argparse import Namespace
3434from typing import TYPE_CHECKING
3535
36- from hatch .cli .cli_utils import EXIT_SUCCESS , EXIT_ERROR , request_confirmation
36+ from hatch .cli .cli_utils import (
37+ EXIT_SUCCESS ,
38+ EXIT_ERROR ,
39+ request_confirmation ,
40+ ResultReporter ,
41+ ConsequenceType ,
42+ )
3743
3844if TYPE_CHECKING :
3945 from hatch .environment_manager import HatchEnvironmentManager
@@ -62,6 +68,19 @@ def handle_env_create(args: Namespace) -> int:
6268 create_python_env = not getattr (args , "no_python" , False )
6369 no_hatch_mcp_server = getattr (args , "no_hatch_mcp_server" , False )
6470 hatch_mcp_server_tag = getattr (args , "hatch_mcp_server_tag" , None )
71+ dry_run = getattr (args , "dry_run" , False )
72+
73+ # Create reporter for unified output
74+ reporter = ResultReporter ("hatch env create" , dry_run = dry_run )
75+ reporter .add (ConsequenceType .CREATE , f"Environment '{ name } '" )
76+
77+ if create_python_env :
78+ version_str = f" ({ python_version } )" if python_version else ""
79+ reporter .add (ConsequenceType .CREATE , f"Python environment{ version_str } " )
80+
81+ if dry_run :
82+ reporter .report_result ()
83+ return EXIT_SUCCESS
6584
6685 if env_manager .create_environment (
6786 name ,
@@ -71,24 +90,17 @@ def handle_env_create(args: Namespace) -> int:
7190 no_hatch_mcp_server = no_hatch_mcp_server ,
7291 hatch_mcp_server_tag = hatch_mcp_server_tag ,
7392 ):
74- print (f"Environment created: { name } " )
75-
76- # Show Python environment status
93+ # Update reporter with actual Python environment details
7794 if create_python_env and env_manager .is_python_environment_available ():
7895 python_exec = env_manager .python_env_manager .get_python_executable (name )
7996 if python_exec :
8097 python_version_info = env_manager .python_env_manager .get_python_version (name )
81- print (f"Python environment: { python_exec } " )
82- if python_version_info :
83- print (f"Python version: { python_version_info } " )
84- else :
85- print ("Python environment creation failed" )
86- elif create_python_env :
87- print ("Python environment requested but conda/mamba not available" )
88-
98+ # Add details as child consequences would be ideal, but for now just report success
99+
100+ reporter .report_result ()
89101 return EXIT_SUCCESS
90102 else :
91- print (f"Failed to create environment: { name } " )
103+ print (f"[ERROR] Failed to create environment: { name } " )
92104 return EXIT_ERROR
93105
94106
@@ -105,12 +117,21 @@ def handle_env_remove(args: Namespace) -> int:
105117 """
106118 env_manager : "HatchEnvironmentManager" = args .env_manager
107119 name = args .name
120+ dry_run = getattr (args , "dry_run" , False )
121+
122+ # Create reporter for unified output
123+ reporter = ResultReporter ("hatch env remove" , dry_run = dry_run )
124+ reporter .add (ConsequenceType .REMOVE , f"Environment '{ name } '" )
125+
126+ if dry_run :
127+ reporter .report_result ()
128+ return EXIT_SUCCESS
108129
109130 if env_manager .remove_environment (name ):
110- print ( f"Environment removed: { name } " )
131+ reporter . report_result ( )
111132 return EXIT_SUCCESS
112133 else :
113- print (f"Failed to remove environment: { name } " )
134+ print (f"[ERROR] Failed to remove environment: { name } " )
114135 return EXIT_ERROR
115136
116137
0 commit comments