Entry Point Module¶
The entry point module (__main__.py) serves as the routing layer for the Hatch CLI, handling argument parsing and command delegation.
Overview¶
This module provides:
- Command-line argument parsing using
argparse - Custom
HatchArgumentParserwith formatted error messages - Manager initialization (HatchEnvironmentManager, MCPHostConfigurationManager)
- Command routing to appropriate handler modules
Module Reference¶
hatch.cli.__main__
¶
Entry point for Hatch CLI.
This module provides the main entry point for the Hatch package manager CLI. It handles argument parsing and routes commands to appropriate handler modules.
Architecture
This module implements the routing layer of the CLI architecture: 1. Parses command-line arguments using argparse 2. Initializes shared managers (HatchEnvironmentManager, MCPHostConfigurationManager) 3. Attaches managers to the args namespace for handler access 4. Routes commands to appropriate handler modules
Command Structure
hatch create
Entry Points
- python -m hatch.cli: Module execution via main.py
- hatch: Console script defined in pyproject.toml
Handler Signature
All handlers follow: (args: Namespace) -> int - args.env_manager: HatchEnvironmentManager instance - args.mcp_manager: MCPHostConfigurationManager instance - Returns: Exit code (0 for success, non-zero for errors)
Example
$ hatch --version $ hatch env list $ hatch mcp configure claude-desktop my-server --command python
Classes¶
HatchArgumentParser
¶
Bases: ArgumentParser
Custom ArgumentParser with formatted error messages.
Overrides the error() method to format argparse errors with [ERROR] prefix and bright red color (when colors enabled).
Reference: R13 §4.2.1 (13-error_message_formatting_v0.md)
Output format
[ERROR]
Example
parser = HatchArgumentParser(description="Test CLI") parser.parse_args(['--invalid']) [ERROR] unrecognized arguments: --invalid
Source code in hatch/cli/__main__.py
Functions¶
error(message)
¶
Override to format errors with [ERROR] prefix and color.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str
|
Error message from argparse |
required |
Note
Preserves exit code 2 (argparse convention).
Source code in hatch/cli/__main__.py
Functions¶
main()
¶
Main entry point for Hatch CLI.
Parses command-line arguments and routes to appropriate handlers for: - Package template creation - Package validation - Environment management - Package management - MCP host configuration
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Exit code (0 for success, 1 for errors) |
Source code in hatch/cli/__main__.py
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 | |