Implement a file-location validator module as specified in the original task. The module should live at pre_commit_hooks/loaderon_hooks/general_hooks/check_location.py and expose a single function:
main(file_path: str) -> None
The function must read CLI configuration from sys.argv to determine allowed directory regex patterns and allowed filenames, and exit with the correct status codes as defined below.
Observed Behavior
The repository currently lacks a fully implemented check_location module and/or does not conform to the exact behavior described in the task. As a result, tests that exercise this functionality fail or are unable to verify the specified CLI-driven validation semantics.
When present, the implementation may not adhere to the precise exit codes, argument handling, or edge-case behavior described in the requirements (e.g., no-argument no-flag scenario, multiple flag occurrences, and directory/file matching rules).
--directories can appear multiple times; each value is a regex pattern (string) used to recognize allowed directories in a file path.
--files can appear multiple times; each value is a file name (basename) that is allowed.
Validation rules:
The number of --directories entries must equal the number of --files entries. If not equal, the program should exit with status code 2.
For the given file_path:
The path must match at least one of the directory regex patterns (using re.search on the full path).
The file name (basename) must exactly equal one of the allowed file names.
If both conditions are met, exit with status code 0.
If either condition fails, exit with status code 2.
No-argument behavior (to satisfy tests that expect a TypeError):
If neither --directories nor --files flags are present in sys.argv, the code should proceed in a way that attempts to iterate over a None value, resulting in a TypeError with message "'NoneType' object is not iterable".
This behavior mirrors tests asserting this specific error when no arguments are provided.
API contract and examples:
Tests call main(file_path) via a test helper.
main should accept exactly one positional argument: the file path to validate.
CLI flags must be consumed from sys.argv, not from any function parameters besides file_path.
Exit codes: 0 for success, 2 for failure as described.
Edge handling:
Multiple flag occurrences must be supported; collect all directory patterns and all file names.
Directory matching uses re.search against the full path for each pattern.
File matching uses a simple basename comparison against the provided file names.
Testing expectations:
Valid configurations and matches should return 0.
Invalid configurations or mismatches should return 2.
A size-mismatch of argument counts (numbers of --directories and --files not equal) should return 2.
No-argument case should raise TypeError "'NoneType' object is not iterable" by attempting to iterate over None.
Deliverables
A self-contained Python module at:
pre_commit_hooks/loaderon_hooks/general_hooks/check_location.py
Implemented main(file_path: str) with the behavior described above.
No external dependencies beyond the Python standard library.
Included comments/docstring explaining the expected CLI arguments and exit behavior.