mdformat icon indicating copy to clipboard operation
mdformat copied to clipboard

Add --config option to specify explicit configuration path

Open meek2100 opened this issue 2 months ago • 0 comments

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:

  1. New CLI Argument: Added --config (type Path) to src/mdformat/_cli.py.
  2. Config Logic: Implemented read_single_config_file in src/mdformat/_conf.py to support direct path loading. The run function logic prioritizes --config and correctly handles non-existent file paths by exiting with an error.
  3. Tests: Added a new test case (test_config_override_precedence) verifying that the explicit --config correctly overrides auto-detected .mdformat.toml settings.
  4. Documentation: Updated docs/users/configuration_file.md to document the new usage.
  5. Code Quality Fix: Corrected the InvalidPath exception class in src/mdformat/_cli.py to properly call super().__init__(path), resolving the flake8-bugbear (B042) warning.

meek2100 avatar Nov 04 '25 21:11 meek2100