Skip to content

Commit b1156e7

Browse files
feat(cli): add confirmation prompt to env remove
1 parent 79da44c commit b1156e7

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

hatch/cli/__main__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def _setup_env_commands(subparsers):
107107
env_remove_parser.add_argument(
108108
"--dry-run", action="store_true", help="Preview changes without execution"
109109
)
110+
env_remove_parser.add_argument(
111+
"--auto-approve", action="store_true", help="Skip confirmation prompt"
112+
)
110113

111114
# List environments command
112115
env_list_parser = env_subparsers.add_parser("list", help="List all available environments")

hatch/cli/cli_env.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,18 @@ def handle_env_remove(args: Namespace) -> int:
113113
args: Namespace with:
114114
- env_manager: HatchEnvironmentManager instance
115115
- name: Environment name to remove
116+
- dry_run: Preview changes without execution
117+
- auto_approve: Skip confirmation prompt
116118
117119
Returns:
118120
Exit code (0 for success, 1 for error)
121+
122+
Reference: R03 §3.1 (03-mutation_output_specification_v0.md)
119123
"""
120124
env_manager: "HatchEnvironmentManager" = args.env_manager
121125
name = args.name
122126
dry_run = getattr(args, "dry_run", False)
127+
auto_approve = getattr(args, "auto_approve", False)
123128

124129
# Create reporter for unified output
125130
reporter = ResultReporter("hatch env remove", dry_run=dry_run)
@@ -129,6 +134,16 @@ def handle_env_remove(args: Namespace) -> int:
129134
reporter.report_result()
130135
return EXIT_SUCCESS
131136

137+
# Show prompt and request confirmation unless auto-approved
138+
if not auto_approve:
139+
prompt = reporter.report_prompt()
140+
if prompt:
141+
print(prompt)
142+
143+
if not request_confirmation("Proceed?"):
144+
print("Operation cancelled.")
145+
return EXIT_SUCCESS
146+
132147
if env_manager.remove_environment(name):
133148
reporter.report_result()
134149
return EXIT_SUCCESS

0 commit comments

Comments
 (0)