hatch-xclam 0.7.1.dev3__py3-none-any.whl → 0.8.0.dev1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hatch/__init__.py +1 -1
- hatch/cli/__init__.py +71 -0
- hatch/cli/__main__.py +1035 -0
- hatch/cli/cli_env.py +865 -0
- hatch/cli/cli_mcp.py +1965 -0
- hatch/cli/cli_package.py +566 -0
- hatch/cli/cli_system.py +136 -0
- hatch/cli/cli_utils.py +1289 -0
- hatch/cli_hatch.py +160 -2838
- hatch/mcp_host_config/__init__.py +10 -10
- hatch/mcp_host_config/adapters/__init__.py +34 -0
- hatch/mcp_host_config/adapters/base.py +170 -0
- hatch/mcp_host_config/adapters/claude.py +105 -0
- hatch/mcp_host_config/adapters/codex.py +104 -0
- hatch/mcp_host_config/adapters/cursor.py +83 -0
- hatch/mcp_host_config/adapters/gemini.py +75 -0
- hatch/mcp_host_config/adapters/kiro.py +78 -0
- hatch/mcp_host_config/adapters/lmstudio.py +79 -0
- hatch/mcp_host_config/adapters/registry.py +149 -0
- hatch/mcp_host_config/adapters/vscode.py +83 -0
- hatch/mcp_host_config/backup.py +5 -3
- hatch/mcp_host_config/fields.py +126 -0
- hatch/mcp_host_config/models.py +161 -456
- hatch/mcp_host_config/reporting.py +57 -16
- hatch/mcp_host_config/strategies.py +155 -87
- hatch/template_generator.py +1 -1
- {hatch_xclam-0.7.1.dev3.dist-info → hatch_xclam-0.8.0.dev1.dist-info}/METADATA +3 -2
- {hatch_xclam-0.7.1.dev3.dist-info → hatch_xclam-0.8.0.dev1.dist-info}/RECORD +52 -43
- {hatch_xclam-0.7.1.dev3.dist-info → hatch_xclam-0.8.0.dev1.dist-info}/WHEEL +1 -1
- hatch_xclam-0.8.0.dev1.dist-info/entry_points.txt +2 -0
- tests/cli_test_utils.py +280 -0
- tests/integration/cli/__init__.py +14 -0
- tests/integration/cli/test_cli_reporter_integration.py +2439 -0
- tests/integration/mcp/__init__.py +0 -0
- tests/integration/mcp/test_adapter_serialization.py +173 -0
- tests/regression/cli/__init__.py +16 -0
- tests/regression/cli/test_color_logic.py +268 -0
- tests/regression/cli/test_consequence_type.py +298 -0
- tests/regression/cli/test_error_formatting.py +328 -0
- tests/regression/cli/test_result_reporter.py +586 -0
- tests/regression/cli/test_table_formatter.py +211 -0
- tests/regression/mcp/__init__.py +0 -0
- tests/regression/mcp/test_field_filtering.py +162 -0
- tests/test_cli_version.py +7 -5
- tests/test_data/fixtures/cli_reporter_fixtures.py +184 -0
- tests/unit/__init__.py +0 -0
- tests/unit/mcp/__init__.py +0 -0
- tests/unit/mcp/test_adapter_protocol.py +138 -0
- tests/unit/mcp/test_adapter_registry.py +158 -0
- tests/unit/mcp/test_config_model.py +146 -0
- hatch_xclam-0.7.1.dev3.dist-info/entry_points.txt +0 -2
- tests/integration/test_mcp_kiro_integration.py +0 -153
- tests/regression/test_mcp_codex_backup_integration.py +0 -162
- tests/regression/test_mcp_codex_host_strategy.py +0 -163
- tests/regression/test_mcp_codex_model_validation.py +0 -117
- tests/regression/test_mcp_kiro_backup_integration.py +0 -241
- tests/regression/test_mcp_kiro_cli_integration.py +0 -141
- tests/regression/test_mcp_kiro_decorator_registration.py +0 -71
- tests/regression/test_mcp_kiro_host_strategy.py +0 -214
- tests/regression/test_mcp_kiro_model_validation.py +0 -116
- tests/regression/test_mcp_kiro_omni_conversion.py +0 -104
- tests/test_mcp_atomic_operations.py +0 -276
- tests/test_mcp_backup_integration.py +0 -308
- tests/test_mcp_cli_all_host_specific_args.py +0 -496
- tests/test_mcp_cli_backup_management.py +0 -295
- tests/test_mcp_cli_direct_management.py +0 -456
- tests/test_mcp_cli_discovery_listing.py +0 -582
- tests/test_mcp_cli_host_config_integration.py +0 -823
- tests/test_mcp_cli_package_management.py +0 -360
- tests/test_mcp_cli_partial_updates.py +0 -859
- tests/test_mcp_environment_integration.py +0 -520
- tests/test_mcp_host_config_backup.py +0 -257
- tests/test_mcp_host_configuration_manager.py +0 -331
- tests/test_mcp_host_registry_decorator.py +0 -348
- tests/test_mcp_pydantic_architecture_v4.py +0 -603
- tests/test_mcp_server_config_models.py +0 -242
- tests/test_mcp_server_config_type_field.py +0 -221
- tests/test_mcp_sync_functionality.py +0 -316
- tests/test_mcp_user_feedback_reporting.py +0 -359
- {hatch_xclam-0.7.1.dev3.dist-info → hatch_xclam-0.8.0.dev1.dist-info}/licenses/LICENSE +0 -0
- {hatch_xclam-0.7.1.dev3.dist-info → hatch_xclam-0.8.0.dev1.dist-info}/top_level.txt +0 -0
hatch/cli/__main__.py
ADDED
|
@@ -0,0 +1,1035 @@
|
|
|
1
|
+
"""Entry point for Hatch CLI.
|
|
2
|
+
|
|
3
|
+
This module provides the main entry point for the Hatch package manager CLI.
|
|
4
|
+
It handles argument parsing and routes commands to appropriate handler modules.
|
|
5
|
+
|
|
6
|
+
Architecture:
|
|
7
|
+
This module implements the routing layer of the CLI architecture:
|
|
8
|
+
1. Parses command-line arguments using argparse
|
|
9
|
+
2. Initializes shared managers (HatchEnvironmentManager, MCPHostConfigurationManager)
|
|
10
|
+
3. Attaches managers to the args namespace for handler access
|
|
11
|
+
4. Routes commands to appropriate handler modules
|
|
12
|
+
|
|
13
|
+
Command Structure:
|
|
14
|
+
hatch create <name> - Create package template (cli_system)
|
|
15
|
+
hatch validate <path> - Validate package (cli_system)
|
|
16
|
+
hatch env <subcommand> - Environment management (cli_env)
|
|
17
|
+
hatch package <subcommand> - Package management (cli_package)
|
|
18
|
+
hatch mcp <subcommand> - MCP host configuration (cli_mcp)
|
|
19
|
+
|
|
20
|
+
Entry Points:
|
|
21
|
+
- python -m hatch.cli: Module execution via __main__.py
|
|
22
|
+
- hatch: Console script defined in pyproject.toml
|
|
23
|
+
|
|
24
|
+
Handler Signature:
|
|
25
|
+
All handlers follow: (args: Namespace) -> int
|
|
26
|
+
- args.env_manager: HatchEnvironmentManager instance
|
|
27
|
+
- args.mcp_manager: MCPHostConfigurationManager instance
|
|
28
|
+
- Returns: Exit code (0 for success, non-zero for errors)
|
|
29
|
+
|
|
30
|
+
Example:
|
|
31
|
+
$ hatch --version
|
|
32
|
+
$ hatch env list
|
|
33
|
+
$ hatch mcp configure claude-desktop my-server --command python
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
import argparse
|
|
37
|
+
import logging
|
|
38
|
+
import sys
|
|
39
|
+
from pathlib import Path
|
|
40
|
+
|
|
41
|
+
from hatch.cli.cli_utils import get_hatch_version, Color, _colors_enabled
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class HatchArgumentParser(argparse.ArgumentParser):
|
|
45
|
+
"""Custom ArgumentParser with formatted error messages.
|
|
46
|
+
|
|
47
|
+
Overrides the error() method to format argparse errors with
|
|
48
|
+
[ERROR] prefix and bright red color (when colors enabled).
|
|
49
|
+
|
|
50
|
+
Reference: R13 §4.2.1 (13-error_message_formatting_v0.md)
|
|
51
|
+
|
|
52
|
+
Output format:
|
|
53
|
+
[ERROR] <message>
|
|
54
|
+
|
|
55
|
+
Example:
|
|
56
|
+
>>> parser = HatchArgumentParser(description="Test CLI")
|
|
57
|
+
>>> parser.parse_args(['--invalid'])
|
|
58
|
+
[ERROR] unrecognized arguments: --invalid
|
|
59
|
+
"""
|
|
60
|
+
|
|
61
|
+
def error(self, message: str) -> None:
|
|
62
|
+
"""Override to format errors with [ERROR] prefix and color.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
message: Error message from argparse
|
|
66
|
+
|
|
67
|
+
Note:
|
|
68
|
+
Preserves exit code 2 (argparse convention).
|
|
69
|
+
"""
|
|
70
|
+
if _colors_enabled():
|
|
71
|
+
self.exit(2, f"{Color.RED.value}[ERROR]{Color.RESET.value} {message}\n")
|
|
72
|
+
else:
|
|
73
|
+
self.exit(2, f"[ERROR] {message}\n")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _setup_create_command(subparsers):
|
|
77
|
+
"""Set up 'hatch create' command parser."""
|
|
78
|
+
create_parser = subparsers.add_parser(
|
|
79
|
+
"create", help="Create a new package template"
|
|
80
|
+
)
|
|
81
|
+
create_parser.add_argument("name", help="Package name")
|
|
82
|
+
create_parser.add_argument(
|
|
83
|
+
"--dir", "-d", default=".", help="Target directory (default: current directory)"
|
|
84
|
+
)
|
|
85
|
+
create_parser.add_argument(
|
|
86
|
+
"--description", "-D", default="", help="Package description"
|
|
87
|
+
)
|
|
88
|
+
create_parser.add_argument(
|
|
89
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def _setup_validate_command(subparsers):
|
|
94
|
+
"""Set up 'hatch validate' command parser."""
|
|
95
|
+
validate_parser = subparsers.add_parser("validate", help="Validate a package")
|
|
96
|
+
validate_parser.add_argument("package_dir", help="Path to package directory")
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def _setup_env_commands(subparsers):
|
|
100
|
+
"""Set up 'hatch env' command parsers."""
|
|
101
|
+
env_subparsers = subparsers.add_parser(
|
|
102
|
+
"env", help="Environment management commands"
|
|
103
|
+
).add_subparsers(dest="env_command", help="Environment command to execute")
|
|
104
|
+
|
|
105
|
+
# Create environment command
|
|
106
|
+
env_create_parser = env_subparsers.add_parser(
|
|
107
|
+
"create", help="Create a new environment"
|
|
108
|
+
)
|
|
109
|
+
env_create_parser.add_argument("name", help="Environment name")
|
|
110
|
+
env_create_parser.add_argument(
|
|
111
|
+
"--description", "-D", default="", help="Environment description"
|
|
112
|
+
)
|
|
113
|
+
env_create_parser.add_argument(
|
|
114
|
+
"--python-version", help="Python version for the environment (e.g., 3.11, 3.12)"
|
|
115
|
+
)
|
|
116
|
+
env_create_parser.add_argument(
|
|
117
|
+
"--no-python",
|
|
118
|
+
action="store_true",
|
|
119
|
+
help="Don't create a Python environment using conda/mamba",
|
|
120
|
+
)
|
|
121
|
+
env_create_parser.add_argument(
|
|
122
|
+
"--no-hatch-mcp-server",
|
|
123
|
+
action="store_true",
|
|
124
|
+
help="Don't install hatch_mcp_server wrapper in the new environment",
|
|
125
|
+
)
|
|
126
|
+
env_create_parser.add_argument(
|
|
127
|
+
"--hatch_mcp_server_tag",
|
|
128
|
+
help="Git tag/branch reference for hatch_mcp_server wrapper installation (e.g., 'dev', 'v0.1.0')",
|
|
129
|
+
)
|
|
130
|
+
env_create_parser.add_argument(
|
|
131
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
# Remove environment command
|
|
135
|
+
env_remove_parser = env_subparsers.add_parser(
|
|
136
|
+
"remove", help="Remove an environment"
|
|
137
|
+
)
|
|
138
|
+
env_remove_parser.add_argument("name", help="Environment name")
|
|
139
|
+
env_remove_parser.add_argument(
|
|
140
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
141
|
+
)
|
|
142
|
+
env_remove_parser.add_argument(
|
|
143
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompt"
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
# List environments command - now with subcommands per R10
|
|
147
|
+
env_list_parser = env_subparsers.add_parser("list", help="List environments, hosts, or servers")
|
|
148
|
+
env_list_subparsers = env_list_parser.add_subparsers(dest="list_command", help="List command to execute")
|
|
149
|
+
|
|
150
|
+
# Default list behavior (no subcommand) - handled by checking list_command is None
|
|
151
|
+
env_list_parser.add_argument(
|
|
152
|
+
"--pattern",
|
|
153
|
+
help="Filter environments by name using regex pattern",
|
|
154
|
+
)
|
|
155
|
+
env_list_parser.add_argument(
|
|
156
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
# env list hosts subcommand per R10 §3.3
|
|
160
|
+
env_list_hosts_parser = env_list_subparsers.add_parser(
|
|
161
|
+
"hosts", help="List environment/host/server deployments"
|
|
162
|
+
)
|
|
163
|
+
env_list_hosts_parser.add_argument(
|
|
164
|
+
"--env", "-e",
|
|
165
|
+
help="Filter by environment name using regex pattern",
|
|
166
|
+
)
|
|
167
|
+
env_list_hosts_parser.add_argument(
|
|
168
|
+
"--server",
|
|
169
|
+
help="Filter by server name using regex pattern",
|
|
170
|
+
)
|
|
171
|
+
env_list_hosts_parser.add_argument(
|
|
172
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
# env list servers subcommand per R10 §3.4
|
|
176
|
+
env_list_servers_parser = env_list_subparsers.add_parser(
|
|
177
|
+
"servers", help="List environment/server/host deployments"
|
|
178
|
+
)
|
|
179
|
+
env_list_servers_parser.add_argument(
|
|
180
|
+
"--env", "-e",
|
|
181
|
+
help="Filter by environment name using regex pattern",
|
|
182
|
+
)
|
|
183
|
+
env_list_servers_parser.add_argument(
|
|
184
|
+
"--host",
|
|
185
|
+
help="Filter by host name using regex pattern (use '-' for undeployed)",
|
|
186
|
+
)
|
|
187
|
+
env_list_servers_parser.add_argument(
|
|
188
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
# Set current environment command
|
|
192
|
+
env_use_parser = env_subparsers.add_parser(
|
|
193
|
+
"use", help="Set the current environment"
|
|
194
|
+
)
|
|
195
|
+
env_use_parser.add_argument("name", help="Environment name")
|
|
196
|
+
env_use_parser.add_argument(
|
|
197
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
# Show current environment command
|
|
201
|
+
env_subparsers.add_parser("current", help="Show the current environment")
|
|
202
|
+
|
|
203
|
+
# Show environment details command
|
|
204
|
+
env_show_parser = env_subparsers.add_parser(
|
|
205
|
+
"show", help="Show detailed environment configuration"
|
|
206
|
+
)
|
|
207
|
+
env_show_parser.add_argument("name", help="Environment name to show")
|
|
208
|
+
|
|
209
|
+
# Python environment management commands
|
|
210
|
+
env_python_subparsers = env_subparsers.add_parser(
|
|
211
|
+
"python", help="Manage Python environments"
|
|
212
|
+
).add_subparsers(
|
|
213
|
+
dest="python_command", help="Python environment command to execute"
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
# Initialize Python environment
|
|
217
|
+
python_init_parser = env_python_subparsers.add_parser(
|
|
218
|
+
"init", help="Initialize Python environment"
|
|
219
|
+
)
|
|
220
|
+
python_init_parser.add_argument(
|
|
221
|
+
"--hatch_env",
|
|
222
|
+
default=None,
|
|
223
|
+
help="Hatch environment name in which the Python environment is located (default: current environment)",
|
|
224
|
+
)
|
|
225
|
+
python_init_parser.add_argument(
|
|
226
|
+
"--python-version", help="Python version (e.g., 3.11, 3.12)"
|
|
227
|
+
)
|
|
228
|
+
python_init_parser.add_argument(
|
|
229
|
+
"--force", action="store_true", help="Force recreation if exists"
|
|
230
|
+
)
|
|
231
|
+
python_init_parser.add_argument(
|
|
232
|
+
"--no-hatch-mcp-server",
|
|
233
|
+
action="store_true",
|
|
234
|
+
help="Don't install hatch_mcp_server wrapper in the Python environment",
|
|
235
|
+
)
|
|
236
|
+
python_init_parser.add_argument(
|
|
237
|
+
"--hatch_mcp_server_tag",
|
|
238
|
+
help="Git tag/branch reference for hatch_mcp_server wrapper installation (e.g., 'dev', 'v0.1.0')",
|
|
239
|
+
)
|
|
240
|
+
python_init_parser.add_argument(
|
|
241
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
# Show Python environment info
|
|
245
|
+
python_info_parser = env_python_subparsers.add_parser(
|
|
246
|
+
"info", help="Show Python environment information"
|
|
247
|
+
)
|
|
248
|
+
python_info_parser.add_argument(
|
|
249
|
+
"--hatch_env",
|
|
250
|
+
default=None,
|
|
251
|
+
help="Hatch environment name in which the Python environment is located (default: current environment)",
|
|
252
|
+
)
|
|
253
|
+
python_info_parser.add_argument(
|
|
254
|
+
"--detailed", action="store_true", help="Show detailed diagnostics"
|
|
255
|
+
)
|
|
256
|
+
|
|
257
|
+
# Hatch MCP server wrapper management
|
|
258
|
+
hatch_mcp_parser = env_python_subparsers.add_parser(
|
|
259
|
+
"add-hatch-mcp", help="Add hatch_mcp_server wrapper to the environment"
|
|
260
|
+
)
|
|
261
|
+
hatch_mcp_parser.add_argument(
|
|
262
|
+
"--hatch_env",
|
|
263
|
+
default=None,
|
|
264
|
+
help="Hatch environment name. It must possess a valid Python environment. (default: current environment)",
|
|
265
|
+
)
|
|
266
|
+
hatch_mcp_parser.add_argument(
|
|
267
|
+
"--tag",
|
|
268
|
+
default=None,
|
|
269
|
+
help="Git tag/branch reference for wrapper installation (e.g., 'dev', 'v0.1.0')",
|
|
270
|
+
)
|
|
271
|
+
hatch_mcp_parser.add_argument(
|
|
272
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
# Remove Python environment
|
|
276
|
+
python_remove_parser = env_python_subparsers.add_parser(
|
|
277
|
+
"remove", help="Remove Python environment"
|
|
278
|
+
)
|
|
279
|
+
python_remove_parser.add_argument(
|
|
280
|
+
"--hatch_env",
|
|
281
|
+
default=None,
|
|
282
|
+
help="Hatch environment name in which the Python environment is located (default: current environment)",
|
|
283
|
+
)
|
|
284
|
+
python_remove_parser.add_argument(
|
|
285
|
+
"--force", action="store_true", help="Force removal without confirmation"
|
|
286
|
+
)
|
|
287
|
+
python_remove_parser.add_argument(
|
|
288
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
# Launch Python shell
|
|
292
|
+
python_shell_parser = env_python_subparsers.add_parser(
|
|
293
|
+
"shell", help="Launch Python shell in environment"
|
|
294
|
+
)
|
|
295
|
+
python_shell_parser.add_argument(
|
|
296
|
+
"--hatch_env",
|
|
297
|
+
default=None,
|
|
298
|
+
help="Hatch environment name in which the Python environment is located (default: current environment)",
|
|
299
|
+
)
|
|
300
|
+
python_shell_parser.add_argument(
|
|
301
|
+
"--cmd", help="Command to run in the shell (optional)"
|
|
302
|
+
)
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _setup_package_commands(subparsers):
|
|
306
|
+
"""Set up 'hatch package' command parsers."""
|
|
307
|
+
pkg_subparsers = subparsers.add_parser(
|
|
308
|
+
"package", help="Package management commands"
|
|
309
|
+
).add_subparsers(dest="pkg_command", help="Package command to execute")
|
|
310
|
+
|
|
311
|
+
# Add package command
|
|
312
|
+
pkg_add_parser = pkg_subparsers.add_parser(
|
|
313
|
+
"add", help="Add a package to the current environment"
|
|
314
|
+
)
|
|
315
|
+
pkg_add_parser.add_argument(
|
|
316
|
+
"package_path_or_name", help="Path to package directory or name of the package"
|
|
317
|
+
)
|
|
318
|
+
pkg_add_parser.add_argument(
|
|
319
|
+
"--env",
|
|
320
|
+
"-e",
|
|
321
|
+
default=None,
|
|
322
|
+
help="Environment name (default: current environment)",
|
|
323
|
+
)
|
|
324
|
+
pkg_add_parser.add_argument(
|
|
325
|
+
"--version", "-v", default=None, help="Version of the package (optional)"
|
|
326
|
+
)
|
|
327
|
+
pkg_add_parser.add_argument(
|
|
328
|
+
"--force-download",
|
|
329
|
+
"-f",
|
|
330
|
+
action="store_true",
|
|
331
|
+
help="Force download even if package is in cache",
|
|
332
|
+
)
|
|
333
|
+
pkg_add_parser.add_argument(
|
|
334
|
+
"--refresh-registry",
|
|
335
|
+
"-r",
|
|
336
|
+
action="store_true",
|
|
337
|
+
help="Force refresh of registry data",
|
|
338
|
+
)
|
|
339
|
+
pkg_add_parser.add_argument(
|
|
340
|
+
"--auto-approve",
|
|
341
|
+
action="store_true",
|
|
342
|
+
help="Automatically approve changes installation of deps for automation scenario",
|
|
343
|
+
)
|
|
344
|
+
pkg_add_parser.add_argument(
|
|
345
|
+
"--host",
|
|
346
|
+
help="Comma-separated list of MCP host platforms to configure (e.g., claude-desktop,cursor)",
|
|
347
|
+
)
|
|
348
|
+
pkg_add_parser.add_argument(
|
|
349
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
# Remove package command
|
|
353
|
+
pkg_remove_parser = pkg_subparsers.add_parser(
|
|
354
|
+
"remove", help="Remove a package from the current environment"
|
|
355
|
+
)
|
|
356
|
+
pkg_remove_parser.add_argument("package_name", help="Name of the package to remove")
|
|
357
|
+
pkg_remove_parser.add_argument(
|
|
358
|
+
"--env",
|
|
359
|
+
"-e",
|
|
360
|
+
default=None,
|
|
361
|
+
help="Environment name (default: current environment)",
|
|
362
|
+
)
|
|
363
|
+
pkg_remove_parser.add_argument(
|
|
364
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
365
|
+
)
|
|
366
|
+
pkg_remove_parser.add_argument(
|
|
367
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompt"
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
# List packages command
|
|
371
|
+
pkg_list_parser = pkg_subparsers.add_parser(
|
|
372
|
+
"list", help="List packages in an environment"
|
|
373
|
+
)
|
|
374
|
+
pkg_list_parser.add_argument(
|
|
375
|
+
"--env", "-e", help="Environment name (default: current environment)"
|
|
376
|
+
)
|
|
377
|
+
|
|
378
|
+
# Sync package MCP servers command
|
|
379
|
+
pkg_sync_parser = pkg_subparsers.add_parser(
|
|
380
|
+
"sync", help="Synchronize package MCP servers to host platforms"
|
|
381
|
+
)
|
|
382
|
+
pkg_sync_parser.add_argument(
|
|
383
|
+
"package_name", help="Name of the package whose MCP servers to sync"
|
|
384
|
+
)
|
|
385
|
+
pkg_sync_parser.add_argument(
|
|
386
|
+
"--host",
|
|
387
|
+
required=True,
|
|
388
|
+
help="Comma-separated list of host platforms to sync to (or 'all')",
|
|
389
|
+
)
|
|
390
|
+
pkg_sync_parser.add_argument(
|
|
391
|
+
"--env",
|
|
392
|
+
"-e",
|
|
393
|
+
default=None,
|
|
394
|
+
help="Environment name (default: current environment)",
|
|
395
|
+
)
|
|
396
|
+
pkg_sync_parser.add_argument(
|
|
397
|
+
"--dry-run", action="store_true", help="Preview changes without execution"
|
|
398
|
+
)
|
|
399
|
+
pkg_sync_parser.add_argument(
|
|
400
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts"
|
|
401
|
+
)
|
|
402
|
+
pkg_sync_parser.add_argument(
|
|
403
|
+
"--no-backup", action="store_true", help="Disable default backup behavior"
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
def _setup_mcp_commands(subparsers):
|
|
408
|
+
"""Set up 'hatch mcp' command parsers."""
|
|
409
|
+
mcp_subparsers = subparsers.add_parser(
|
|
410
|
+
"mcp", help="MCP host configuration commands"
|
|
411
|
+
).add_subparsers(dest="mcp_command", help="MCP command to execute")
|
|
412
|
+
|
|
413
|
+
# MCP discovery commands
|
|
414
|
+
mcp_discover_subparsers = mcp_subparsers.add_parser(
|
|
415
|
+
"discover", help="Discover MCP hosts and servers"
|
|
416
|
+
).add_subparsers(dest="discover_command", help="Discovery command to execute")
|
|
417
|
+
|
|
418
|
+
# Discover hosts command
|
|
419
|
+
mcp_discover_hosts_parser = mcp_discover_subparsers.add_parser(
|
|
420
|
+
"hosts", help="Discover available MCP host platforms"
|
|
421
|
+
)
|
|
422
|
+
mcp_discover_hosts_parser.add_argument(
|
|
423
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
424
|
+
)
|
|
425
|
+
|
|
426
|
+
# Discover servers command
|
|
427
|
+
mcp_discover_servers_parser = mcp_discover_subparsers.add_parser(
|
|
428
|
+
"servers", help="Discover configured MCP servers"
|
|
429
|
+
)
|
|
430
|
+
mcp_discover_servers_parser.add_argument(
|
|
431
|
+
"--env",
|
|
432
|
+
"-e",
|
|
433
|
+
default=None,
|
|
434
|
+
help="Environment name (default: current environment)",
|
|
435
|
+
)
|
|
436
|
+
|
|
437
|
+
# MCP list commands
|
|
438
|
+
mcp_list_subparsers = mcp_subparsers.add_parser(
|
|
439
|
+
"list", help="List MCP hosts and servers"
|
|
440
|
+
).add_subparsers(dest="list_command", help="List command to execute")
|
|
441
|
+
|
|
442
|
+
# List hosts command - host-centric design per R10 §3.1
|
|
443
|
+
mcp_list_hosts_parser = mcp_list_subparsers.add_parser(
|
|
444
|
+
"hosts", help="List host/server pairs from host configuration files"
|
|
445
|
+
)
|
|
446
|
+
mcp_list_hosts_parser.add_argument(
|
|
447
|
+
"--server",
|
|
448
|
+
help="Filter by server name using regex pattern",
|
|
449
|
+
)
|
|
450
|
+
mcp_list_hosts_parser.add_argument(
|
|
451
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
452
|
+
)
|
|
453
|
+
|
|
454
|
+
# List servers command - per R10 §3.2 (--pattern removed, use mcp list hosts --server instead)
|
|
455
|
+
mcp_list_servers_parser = mcp_list_subparsers.add_parser(
|
|
456
|
+
"servers", help="List server/host pairs from host configuration files"
|
|
457
|
+
)
|
|
458
|
+
mcp_list_servers_parser.add_argument(
|
|
459
|
+
"--host",
|
|
460
|
+
help="Filter by host name using regex pattern",
|
|
461
|
+
)
|
|
462
|
+
mcp_list_servers_parser.add_argument(
|
|
463
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
# MCP show commands (detailed views) - per R11 specification
|
|
467
|
+
mcp_show_subparsers = mcp_subparsers.add_parser(
|
|
468
|
+
"show", help="Show detailed MCP host or server configuration"
|
|
469
|
+
).add_subparsers(dest="show_command", help="Show command to execute")
|
|
470
|
+
|
|
471
|
+
# Show hosts command - host-centric detailed view per R11 §2.1
|
|
472
|
+
mcp_show_hosts_parser = mcp_show_subparsers.add_parser(
|
|
473
|
+
"hosts", help="Show detailed host configurations"
|
|
474
|
+
)
|
|
475
|
+
mcp_show_hosts_parser.add_argument(
|
|
476
|
+
"--server",
|
|
477
|
+
help="Filter by server name using regex pattern",
|
|
478
|
+
)
|
|
479
|
+
mcp_show_hosts_parser.add_argument(
|
|
480
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
481
|
+
)
|
|
482
|
+
|
|
483
|
+
# Show servers command - server-centric detailed view per R11 §2.2
|
|
484
|
+
mcp_show_servers_parser = mcp_show_subparsers.add_parser(
|
|
485
|
+
"servers", help="Show detailed server configurations across hosts"
|
|
486
|
+
)
|
|
487
|
+
mcp_show_servers_parser.add_argument(
|
|
488
|
+
"--host",
|
|
489
|
+
help="Filter by host name using regex pattern",
|
|
490
|
+
)
|
|
491
|
+
mcp_show_servers_parser.add_argument(
|
|
492
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
493
|
+
)
|
|
494
|
+
|
|
495
|
+
# MCP backup commands
|
|
496
|
+
mcp_backup_subparsers = mcp_subparsers.add_parser(
|
|
497
|
+
"backup", help="Backup management commands"
|
|
498
|
+
).add_subparsers(dest="backup_command", help="Backup command to execute")
|
|
499
|
+
|
|
500
|
+
# Restore backup command
|
|
501
|
+
mcp_backup_restore_parser = mcp_backup_subparsers.add_parser(
|
|
502
|
+
"restore", help="Restore MCP host configuration from backup"
|
|
503
|
+
)
|
|
504
|
+
mcp_backup_restore_parser.add_argument(
|
|
505
|
+
"host", help="Host platform to restore (e.g., claude-desktop, cursor)"
|
|
506
|
+
)
|
|
507
|
+
mcp_backup_restore_parser.add_argument(
|
|
508
|
+
"--backup-file",
|
|
509
|
+
"-f",
|
|
510
|
+
default=None,
|
|
511
|
+
help="Specific backup file to restore (default: latest)",
|
|
512
|
+
)
|
|
513
|
+
mcp_backup_restore_parser.add_argument(
|
|
514
|
+
"--dry-run",
|
|
515
|
+
action="store_true",
|
|
516
|
+
help="Preview restore operation without execution",
|
|
517
|
+
)
|
|
518
|
+
mcp_backup_restore_parser.add_argument(
|
|
519
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts"
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
# List backups command
|
|
523
|
+
mcp_backup_list_parser = mcp_backup_subparsers.add_parser(
|
|
524
|
+
"list", help="List available backups for MCP host"
|
|
525
|
+
)
|
|
526
|
+
mcp_backup_list_parser.add_argument(
|
|
527
|
+
"host", help="Host platform to list backups for (e.g., claude-desktop, cursor)"
|
|
528
|
+
)
|
|
529
|
+
mcp_backup_list_parser.add_argument(
|
|
530
|
+
"--detailed", "-d", action="store_true", help="Show detailed backup information"
|
|
531
|
+
)
|
|
532
|
+
mcp_backup_list_parser.add_argument(
|
|
533
|
+
"--json", action="store_true", help="Output in JSON format"
|
|
534
|
+
)
|
|
535
|
+
|
|
536
|
+
# Clean backups command
|
|
537
|
+
mcp_backup_clean_parser = mcp_backup_subparsers.add_parser(
|
|
538
|
+
"clean", help="Clean old backups based on criteria"
|
|
539
|
+
)
|
|
540
|
+
mcp_backup_clean_parser.add_argument(
|
|
541
|
+
"host", help="Host platform to clean backups for (e.g., claude-desktop, cursor)"
|
|
542
|
+
)
|
|
543
|
+
mcp_backup_clean_parser.add_argument(
|
|
544
|
+
"--older-than-days", type=int, help="Remove backups older than specified days"
|
|
545
|
+
)
|
|
546
|
+
mcp_backup_clean_parser.add_argument(
|
|
547
|
+
"--keep-count",
|
|
548
|
+
type=int,
|
|
549
|
+
help="Keep only the specified number of newest backups",
|
|
550
|
+
)
|
|
551
|
+
mcp_backup_clean_parser.add_argument(
|
|
552
|
+
"--dry-run",
|
|
553
|
+
action="store_true",
|
|
554
|
+
help="Preview cleanup operation without execution",
|
|
555
|
+
)
|
|
556
|
+
mcp_backup_clean_parser.add_argument(
|
|
557
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts"
|
|
558
|
+
)
|
|
559
|
+
|
|
560
|
+
# MCP configure command
|
|
561
|
+
mcp_configure_parser = mcp_subparsers.add_parser(
|
|
562
|
+
"configure", help="Configure MCP server directly on host"
|
|
563
|
+
)
|
|
564
|
+
mcp_configure_parser.add_argument(
|
|
565
|
+
"server_name", help="Name for the MCP server [hosts: all]"
|
|
566
|
+
)
|
|
567
|
+
mcp_configure_parser.add_argument(
|
|
568
|
+
"--host",
|
|
569
|
+
required=True,
|
|
570
|
+
help="Host platform to configure (e.g., claude-desktop, cursor) [hosts: all]",
|
|
571
|
+
)
|
|
572
|
+
|
|
573
|
+
# Create mutually exclusive group for server type
|
|
574
|
+
server_type_group = mcp_configure_parser.add_mutually_exclusive_group()
|
|
575
|
+
server_type_group.add_argument(
|
|
576
|
+
"--command",
|
|
577
|
+
dest="server_command",
|
|
578
|
+
help="Command to execute the MCP server (for local servers) [hosts: all]",
|
|
579
|
+
)
|
|
580
|
+
server_type_group.add_argument(
|
|
581
|
+
"--url", help="Server URL for remote MCP servers (SSE transport) [hosts: all except claude-desktop, claude-code]"
|
|
582
|
+
)
|
|
583
|
+
server_type_group.add_argument(
|
|
584
|
+
"--http-url", help="HTTP streaming endpoint URL [hosts: gemini]"
|
|
585
|
+
)
|
|
586
|
+
|
|
587
|
+
mcp_configure_parser.add_argument(
|
|
588
|
+
"--args",
|
|
589
|
+
nargs="*",
|
|
590
|
+
help="Arguments for the MCP server command (only with --command) [hosts: all]",
|
|
591
|
+
)
|
|
592
|
+
mcp_configure_parser.add_argument(
|
|
593
|
+
"--env-var",
|
|
594
|
+
action="append",
|
|
595
|
+
help="Environment variables (format: KEY=VALUE) [hosts: all]",
|
|
596
|
+
)
|
|
597
|
+
mcp_configure_parser.add_argument(
|
|
598
|
+
"--header",
|
|
599
|
+
action="append",
|
|
600
|
+
help="HTTP headers for remote servers (format: KEY=VALUE, only with --url) [hosts: all except claude-desktop, claude-code]",
|
|
601
|
+
)
|
|
602
|
+
|
|
603
|
+
# Host-specific arguments (Gemini)
|
|
604
|
+
mcp_configure_parser.add_argument(
|
|
605
|
+
"--timeout", type=int, help="Request timeout in milliseconds [hosts: gemini]"
|
|
606
|
+
)
|
|
607
|
+
mcp_configure_parser.add_argument(
|
|
608
|
+
"--trust", action="store_true", help="Bypass tool call confirmations [hosts: gemini]"
|
|
609
|
+
)
|
|
610
|
+
mcp_configure_parser.add_argument(
|
|
611
|
+
"--cwd", help="Working directory for stdio transport [hosts: gemini, codex]"
|
|
612
|
+
)
|
|
613
|
+
mcp_configure_parser.add_argument(
|
|
614
|
+
"--include-tools",
|
|
615
|
+
nargs="*",
|
|
616
|
+
help="Tool allowlist / enabled tools [hosts: gemini, codex]",
|
|
617
|
+
)
|
|
618
|
+
mcp_configure_parser.add_argument(
|
|
619
|
+
"--exclude-tools",
|
|
620
|
+
nargs="*",
|
|
621
|
+
help="Tool blocklist / disabled tools [hosts: gemini, codex]",
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
# Host-specific arguments (Cursor/VS Code/LM Studio)
|
|
625
|
+
mcp_configure_parser.add_argument(
|
|
626
|
+
"--env-file", help="Path to environment file [hosts: cursor, vscode, lmstudio]"
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
# Host-specific arguments (VS Code)
|
|
630
|
+
mcp_configure_parser.add_argument(
|
|
631
|
+
"--input",
|
|
632
|
+
action="append",
|
|
633
|
+
help="Input variable definitions in format: type,id,description[,password=true] [hosts: vscode]",
|
|
634
|
+
)
|
|
635
|
+
|
|
636
|
+
# Host-specific arguments (Kiro)
|
|
637
|
+
mcp_configure_parser.add_argument(
|
|
638
|
+
"--disabled",
|
|
639
|
+
action="store_true",
|
|
640
|
+
default=None,
|
|
641
|
+
help="Disable the MCP server [hosts: kiro]"
|
|
642
|
+
)
|
|
643
|
+
mcp_configure_parser.add_argument(
|
|
644
|
+
"--auto-approve-tools",
|
|
645
|
+
action="append",
|
|
646
|
+
help="Tool names to auto-approve without prompting [hosts: kiro]"
|
|
647
|
+
)
|
|
648
|
+
mcp_configure_parser.add_argument(
|
|
649
|
+
"--disable-tools",
|
|
650
|
+
action="append",
|
|
651
|
+
help="Tool names to disable [hosts: kiro]"
|
|
652
|
+
)
|
|
653
|
+
|
|
654
|
+
# Codex-specific arguments
|
|
655
|
+
mcp_configure_parser.add_argument(
|
|
656
|
+
"--env-vars",
|
|
657
|
+
action="append",
|
|
658
|
+
help="Environment variable names to whitelist/forward [hosts: codex]"
|
|
659
|
+
)
|
|
660
|
+
mcp_configure_parser.add_argument(
|
|
661
|
+
"--startup-timeout",
|
|
662
|
+
type=int,
|
|
663
|
+
help="Server startup timeout in seconds (default: 10) [hosts: codex]"
|
|
664
|
+
)
|
|
665
|
+
mcp_configure_parser.add_argument(
|
|
666
|
+
"--tool-timeout",
|
|
667
|
+
type=int,
|
|
668
|
+
help="Tool execution timeout in seconds (default: 60) [hosts: codex]"
|
|
669
|
+
)
|
|
670
|
+
mcp_configure_parser.add_argument(
|
|
671
|
+
"--enabled",
|
|
672
|
+
action="store_true",
|
|
673
|
+
default=None,
|
|
674
|
+
help="Enable the MCP server [hosts: codex]"
|
|
675
|
+
)
|
|
676
|
+
mcp_configure_parser.add_argument(
|
|
677
|
+
"--bearer-token-env-var",
|
|
678
|
+
type=str,
|
|
679
|
+
help="Name of environment variable containing bearer token for Authorization header [hosts: codex]"
|
|
680
|
+
)
|
|
681
|
+
mcp_configure_parser.add_argument(
|
|
682
|
+
"--env-header",
|
|
683
|
+
action="append",
|
|
684
|
+
help="HTTP header from environment variable in KEY=ENV_VAR_NAME format [hosts: codex]"
|
|
685
|
+
)
|
|
686
|
+
|
|
687
|
+
mcp_configure_parser.add_argument(
|
|
688
|
+
"--no-backup",
|
|
689
|
+
action="store_true",
|
|
690
|
+
help="Skip backup creation before configuration [hosts: all]",
|
|
691
|
+
)
|
|
692
|
+
mcp_configure_parser.add_argument(
|
|
693
|
+
"--dry-run", action="store_true", help="Preview configuration without execution [hosts: all]"
|
|
694
|
+
)
|
|
695
|
+
mcp_configure_parser.add_argument(
|
|
696
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts [hosts: all]"
|
|
697
|
+
)
|
|
698
|
+
|
|
699
|
+
# MCP remove commands
|
|
700
|
+
mcp_remove_subparsers = mcp_subparsers.add_parser(
|
|
701
|
+
"remove", help="Remove MCP servers or host configurations"
|
|
702
|
+
).add_subparsers(dest="remove_command", help="Remove command to execute")
|
|
703
|
+
|
|
704
|
+
# Remove server command
|
|
705
|
+
mcp_remove_server_parser = mcp_remove_subparsers.add_parser(
|
|
706
|
+
"server", help="Remove MCP server from hosts"
|
|
707
|
+
)
|
|
708
|
+
mcp_remove_server_parser.add_argument(
|
|
709
|
+
"server_name", help="Name of the MCP server to remove"
|
|
710
|
+
)
|
|
711
|
+
mcp_remove_server_parser.add_argument(
|
|
712
|
+
"--host", help="Target hosts (comma-separated or 'all')"
|
|
713
|
+
)
|
|
714
|
+
mcp_remove_server_parser.add_argument(
|
|
715
|
+
"--env", "-e", help="Environment name (for environment-based removal)"
|
|
716
|
+
)
|
|
717
|
+
mcp_remove_server_parser.add_argument(
|
|
718
|
+
"--no-backup", action="store_true", help="Skip backup creation before removal"
|
|
719
|
+
)
|
|
720
|
+
mcp_remove_server_parser.add_argument(
|
|
721
|
+
"--dry-run", action="store_true", help="Preview removal without execution"
|
|
722
|
+
)
|
|
723
|
+
mcp_remove_server_parser.add_argument(
|
|
724
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts"
|
|
725
|
+
)
|
|
726
|
+
|
|
727
|
+
# Remove host command
|
|
728
|
+
mcp_remove_host_parser = mcp_remove_subparsers.add_parser(
|
|
729
|
+
"host", help="Remove entire host configuration"
|
|
730
|
+
)
|
|
731
|
+
mcp_remove_host_parser.add_argument(
|
|
732
|
+
"host_name", help="Host platform to remove (e.g., claude-desktop, cursor)"
|
|
733
|
+
)
|
|
734
|
+
mcp_remove_host_parser.add_argument(
|
|
735
|
+
"--no-backup", action="store_true", help="Skip backup creation before removal"
|
|
736
|
+
)
|
|
737
|
+
mcp_remove_host_parser.add_argument(
|
|
738
|
+
"--dry-run", action="store_true", help="Preview removal without execution"
|
|
739
|
+
)
|
|
740
|
+
mcp_remove_host_parser.add_argument(
|
|
741
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts"
|
|
742
|
+
)
|
|
743
|
+
|
|
744
|
+
# MCP sync command
|
|
745
|
+
mcp_sync_parser = mcp_subparsers.add_parser(
|
|
746
|
+
"sync", help="Synchronize MCP configurations between environments and hosts"
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
# Source options (mutually exclusive)
|
|
750
|
+
sync_source_group = mcp_sync_parser.add_mutually_exclusive_group(required=True)
|
|
751
|
+
sync_source_group.add_argument("--from-env", help="Source environment name")
|
|
752
|
+
sync_source_group.add_argument("--from-host", help="Source host platform")
|
|
753
|
+
|
|
754
|
+
# Target options
|
|
755
|
+
mcp_sync_parser.add_argument(
|
|
756
|
+
"--to-host", required=True, help="Target hosts (comma-separated or 'all')"
|
|
757
|
+
)
|
|
758
|
+
|
|
759
|
+
# Filter options (mutually exclusive)
|
|
760
|
+
sync_filter_group = mcp_sync_parser.add_mutually_exclusive_group()
|
|
761
|
+
sync_filter_group.add_argument(
|
|
762
|
+
"--servers", help="Specific server names to sync (comma-separated)"
|
|
763
|
+
)
|
|
764
|
+
sync_filter_group.add_argument(
|
|
765
|
+
"--pattern", help="Regex pattern for server selection"
|
|
766
|
+
)
|
|
767
|
+
|
|
768
|
+
# Standard options
|
|
769
|
+
mcp_sync_parser.add_argument(
|
|
770
|
+
"--dry-run",
|
|
771
|
+
action="store_true",
|
|
772
|
+
help="Preview synchronization without execution",
|
|
773
|
+
)
|
|
774
|
+
mcp_sync_parser.add_argument(
|
|
775
|
+
"--auto-approve", action="store_true", help="Skip confirmation prompts"
|
|
776
|
+
)
|
|
777
|
+
mcp_sync_parser.add_argument(
|
|
778
|
+
"--no-backup",
|
|
779
|
+
action="store_true",
|
|
780
|
+
help="Skip backup creation before synchronization",
|
|
781
|
+
)
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def _route_env_command(args):
|
|
785
|
+
"""Route environment commands to handlers."""
|
|
786
|
+
from hatch.cli.cli_env import (
|
|
787
|
+
handle_env_create,
|
|
788
|
+
handle_env_remove,
|
|
789
|
+
handle_env_list,
|
|
790
|
+
handle_env_list_hosts,
|
|
791
|
+
handle_env_list_servers,
|
|
792
|
+
handle_env_use,
|
|
793
|
+
handle_env_current,
|
|
794
|
+
handle_env_show,
|
|
795
|
+
handle_env_python_init,
|
|
796
|
+
handle_env_python_info,
|
|
797
|
+
handle_env_python_remove,
|
|
798
|
+
handle_env_python_shell,
|
|
799
|
+
handle_env_python_add_hatch_mcp,
|
|
800
|
+
)
|
|
801
|
+
|
|
802
|
+
if args.env_command == "create":
|
|
803
|
+
return handle_env_create(args)
|
|
804
|
+
elif args.env_command == "remove":
|
|
805
|
+
return handle_env_remove(args)
|
|
806
|
+
elif args.env_command == "list":
|
|
807
|
+
# Check for subcommand (hosts, servers) or default list behavior
|
|
808
|
+
list_command = getattr(args, 'list_command', None)
|
|
809
|
+
if list_command == "hosts":
|
|
810
|
+
return handle_env_list_hosts(args)
|
|
811
|
+
elif list_command == "servers":
|
|
812
|
+
return handle_env_list_servers(args)
|
|
813
|
+
else:
|
|
814
|
+
# Default: list environments
|
|
815
|
+
return handle_env_list(args)
|
|
816
|
+
elif args.env_command == "use":
|
|
817
|
+
return handle_env_use(args)
|
|
818
|
+
elif args.env_command == "current":
|
|
819
|
+
return handle_env_current(args)
|
|
820
|
+
elif args.env_command == "show":
|
|
821
|
+
return handle_env_show(args)
|
|
822
|
+
elif args.env_command == "python":
|
|
823
|
+
if args.python_command == "init":
|
|
824
|
+
return handle_env_python_init(args)
|
|
825
|
+
elif args.python_command == "info":
|
|
826
|
+
return handle_env_python_info(args)
|
|
827
|
+
elif args.python_command == "remove":
|
|
828
|
+
return handle_env_python_remove(args)
|
|
829
|
+
elif args.python_command == "shell":
|
|
830
|
+
return handle_env_python_shell(args)
|
|
831
|
+
elif args.python_command == "add-hatch-mcp":
|
|
832
|
+
return handle_env_python_add_hatch_mcp(args)
|
|
833
|
+
else:
|
|
834
|
+
print("Unknown Python environment command")
|
|
835
|
+
return 1
|
|
836
|
+
else:
|
|
837
|
+
print("Unknown environment command")
|
|
838
|
+
return 1
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
def _route_package_command(args):
|
|
842
|
+
"""Route package commands to handlers."""
|
|
843
|
+
from hatch.cli.cli_package import (
|
|
844
|
+
handle_package_add,
|
|
845
|
+
handle_package_remove,
|
|
846
|
+
handle_package_list,
|
|
847
|
+
handle_package_sync,
|
|
848
|
+
)
|
|
849
|
+
|
|
850
|
+
if args.pkg_command == "add":
|
|
851
|
+
return handle_package_add(args)
|
|
852
|
+
elif args.pkg_command == "remove":
|
|
853
|
+
return handle_package_remove(args)
|
|
854
|
+
elif args.pkg_command == "list":
|
|
855
|
+
return handle_package_list(args)
|
|
856
|
+
elif args.pkg_command == "sync":
|
|
857
|
+
return handle_package_sync(args)
|
|
858
|
+
else:
|
|
859
|
+
print("Unknown package command")
|
|
860
|
+
return 1
|
|
861
|
+
|
|
862
|
+
|
|
863
|
+
def _route_mcp_command(args):
|
|
864
|
+
"""Route MCP commands to handlers."""
|
|
865
|
+
from hatch.cli.cli_mcp import (
|
|
866
|
+
handle_mcp_discover_hosts,
|
|
867
|
+
handle_mcp_discover_servers,
|
|
868
|
+
handle_mcp_list_hosts,
|
|
869
|
+
handle_mcp_list_servers,
|
|
870
|
+
handle_mcp_show_hosts,
|
|
871
|
+
handle_mcp_show_servers,
|
|
872
|
+
handle_mcp_backup_restore,
|
|
873
|
+
handle_mcp_backup_list,
|
|
874
|
+
handle_mcp_backup_clean,
|
|
875
|
+
handle_mcp_configure,
|
|
876
|
+
handle_mcp_remove_server,
|
|
877
|
+
handle_mcp_remove_host,
|
|
878
|
+
handle_mcp_sync,
|
|
879
|
+
)
|
|
880
|
+
|
|
881
|
+
if args.mcp_command == "discover":
|
|
882
|
+
if args.discover_command == "hosts":
|
|
883
|
+
return handle_mcp_discover_hosts(args)
|
|
884
|
+
elif args.discover_command == "servers":
|
|
885
|
+
return handle_mcp_discover_servers(args)
|
|
886
|
+
else:
|
|
887
|
+
print("Unknown discover command")
|
|
888
|
+
return 1
|
|
889
|
+
|
|
890
|
+
elif args.mcp_command == "list":
|
|
891
|
+
if args.list_command == "hosts":
|
|
892
|
+
return handle_mcp_list_hosts(args)
|
|
893
|
+
elif args.list_command == "servers":
|
|
894
|
+
return handle_mcp_list_servers(args)
|
|
895
|
+
else:
|
|
896
|
+
print("Unknown list command")
|
|
897
|
+
return 1
|
|
898
|
+
|
|
899
|
+
elif args.mcp_command == "show":
|
|
900
|
+
show_command = getattr(args, 'show_command', None)
|
|
901
|
+
if show_command == "hosts":
|
|
902
|
+
return handle_mcp_show_hosts(args)
|
|
903
|
+
elif show_command == "servers":
|
|
904
|
+
return handle_mcp_show_servers(args)
|
|
905
|
+
else:
|
|
906
|
+
print("Unknown show command. Use 'hatch mcp show hosts' or 'hatch mcp show servers'")
|
|
907
|
+
return 1
|
|
908
|
+
|
|
909
|
+
elif args.mcp_command == "backup":
|
|
910
|
+
if args.backup_command == "restore":
|
|
911
|
+
return handle_mcp_backup_restore(args)
|
|
912
|
+
elif args.backup_command == "list":
|
|
913
|
+
return handle_mcp_backup_list(args)
|
|
914
|
+
elif args.backup_command == "clean":
|
|
915
|
+
return handle_mcp_backup_clean(args)
|
|
916
|
+
else:
|
|
917
|
+
print("Unknown backup command")
|
|
918
|
+
return 1
|
|
919
|
+
|
|
920
|
+
elif args.mcp_command == "configure":
|
|
921
|
+
return handle_mcp_configure(args)
|
|
922
|
+
|
|
923
|
+
elif args.mcp_command == "remove":
|
|
924
|
+
if args.remove_command == "server":
|
|
925
|
+
return handle_mcp_remove_server(args)
|
|
926
|
+
elif args.remove_command == "host":
|
|
927
|
+
return handle_mcp_remove_host(args)
|
|
928
|
+
else:
|
|
929
|
+
print("Unknown remove command")
|
|
930
|
+
return 1
|
|
931
|
+
|
|
932
|
+
elif args.mcp_command == "sync":
|
|
933
|
+
return handle_mcp_sync(args)
|
|
934
|
+
|
|
935
|
+
else:
|
|
936
|
+
print("Unknown MCP command")
|
|
937
|
+
return 1
|
|
938
|
+
|
|
939
|
+
|
|
940
|
+
def main() -> int:
|
|
941
|
+
"""Main entry point for Hatch CLI.
|
|
942
|
+
|
|
943
|
+
Parses command-line arguments and routes to appropriate handlers for:
|
|
944
|
+
- Package template creation
|
|
945
|
+
- Package validation
|
|
946
|
+
- Environment management
|
|
947
|
+
- Package management
|
|
948
|
+
- MCP host configuration
|
|
949
|
+
|
|
950
|
+
Returns:
|
|
951
|
+
int: Exit code (0 for success, 1 for errors)
|
|
952
|
+
"""
|
|
953
|
+
# Configure logging
|
|
954
|
+
logging.basicConfig(
|
|
955
|
+
level=logging.INFO,
|
|
956
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
957
|
+
)
|
|
958
|
+
|
|
959
|
+
# Create argument parser
|
|
960
|
+
parser = HatchArgumentParser(description="Hatch package manager CLI")
|
|
961
|
+
|
|
962
|
+
# Add version argument
|
|
963
|
+
parser.add_argument(
|
|
964
|
+
"--version", action="version", version=f"%(prog)s {get_hatch_version()}"
|
|
965
|
+
)
|
|
966
|
+
|
|
967
|
+
subparsers = parser.add_subparsers(dest="command", help="Command to execute")
|
|
968
|
+
|
|
969
|
+
# Set up command parsers
|
|
970
|
+
_setup_create_command(subparsers)
|
|
971
|
+
_setup_validate_command(subparsers)
|
|
972
|
+
_setup_env_commands(subparsers)
|
|
973
|
+
_setup_package_commands(subparsers)
|
|
974
|
+
_setup_mcp_commands(subparsers)
|
|
975
|
+
|
|
976
|
+
# General arguments for the environment manager
|
|
977
|
+
parser.add_argument(
|
|
978
|
+
"--envs-dir",
|
|
979
|
+
default=Path.home() / ".hatch" / "envs",
|
|
980
|
+
help="Directory to store environments",
|
|
981
|
+
)
|
|
982
|
+
parser.add_argument(
|
|
983
|
+
"--cache-ttl",
|
|
984
|
+
type=int,
|
|
985
|
+
default=86400,
|
|
986
|
+
help="Cache TTL in seconds (default: 86400 seconds --> 1 day)",
|
|
987
|
+
)
|
|
988
|
+
parser.add_argument(
|
|
989
|
+
"--cache-dir",
|
|
990
|
+
default=Path.home() / ".hatch" / "cache",
|
|
991
|
+
help="Directory to store cached packages",
|
|
992
|
+
)
|
|
993
|
+
|
|
994
|
+
args = parser.parse_args()
|
|
995
|
+
|
|
996
|
+
# Initialize managers (lazy - only when needed)
|
|
997
|
+
from hatch.environment_manager import HatchEnvironmentManager
|
|
998
|
+
from hatch.mcp_host_config import MCPHostConfigurationManager
|
|
999
|
+
|
|
1000
|
+
env_manager = HatchEnvironmentManager(
|
|
1001
|
+
environments_dir=args.envs_dir,
|
|
1002
|
+
cache_ttl=args.cache_ttl,
|
|
1003
|
+
cache_dir=args.cache_dir,
|
|
1004
|
+
)
|
|
1005
|
+
mcp_manager = MCPHostConfigurationManager()
|
|
1006
|
+
|
|
1007
|
+
# Attach managers to args for handler access
|
|
1008
|
+
args.env_manager = env_manager
|
|
1009
|
+
args.mcp_manager = mcp_manager
|
|
1010
|
+
|
|
1011
|
+
# Route commands
|
|
1012
|
+
if args.command == "create":
|
|
1013
|
+
from hatch.cli.cli_system import handle_create
|
|
1014
|
+
return handle_create(args)
|
|
1015
|
+
|
|
1016
|
+
elif args.command == "validate":
|
|
1017
|
+
from hatch.cli.cli_system import handle_validate
|
|
1018
|
+
return handle_validate(args)
|
|
1019
|
+
|
|
1020
|
+
elif args.command == "env":
|
|
1021
|
+
return _route_env_command(args)
|
|
1022
|
+
|
|
1023
|
+
elif args.command == "package":
|
|
1024
|
+
return _route_package_command(args)
|
|
1025
|
+
|
|
1026
|
+
elif args.command == "mcp":
|
|
1027
|
+
return _route_mcp_command(args)
|
|
1028
|
+
|
|
1029
|
+
else:
|
|
1030
|
+
parser.print_help()
|
|
1031
|
+
return 1
|
|
1032
|
+
|
|
1033
|
+
|
|
1034
|
+
if __name__ == "__main__":
|
|
1035
|
+
sys.exit(main())
|