mdformat
mdformat copied to clipboard
Add --config option to specify explicit configuration path
This pull request introduces the --config <path> command-line option, allowing users to explicitly define the path to their TOML configuration file, overriding the default recursive search for .mdformat.toml.
This feature primarily supports integration with modern tooling like pre-commit hooks and centralized configuration management systems where config files may live outside the project root or in a custom directory.
Key Changes:
-
New CLI Argument: Added
--config(typePath) tosrc/mdformat/_cli.py. -
Config Logic: Implemented
read_single_config_fileinsrc/mdformat/_conf.pyto support direct path loading. Therunfunction logic prioritizes--configand correctly handles non-existent file paths by exiting with an error. -
Tests: Added a new test case (
test_config_override_precedence) verifying that the explicit--configcorrectly overrides auto-detected.mdformat.tomlsettings. -
Documentation: Updated
docs/users/configuration_file.mdto document the new usage. -
Code Quality Fix: Corrected the
InvalidPathexception class insrc/mdformat/_cli.pyto properly callsuper().__init__(path), resolving theflake8-bugbear(B042) warning.