Reduce code complexity of category.main()
Description:
The main() function in scripts/category.py has grown too large and complex over time. It currently triggers a C901 ("function is too complex") warning when running code quality checks (flake8/mccabe).
High complexity makes the function harder to understand, test, and maintain. In particular:
Multiple nested conditionals and loops
Several distinct responsibilities handled in one function
Many edge cases mixed into the main execution flow
Suggested improvements:
Split main() into smaller helper functions, each handling a specific concern (argument parsing, summary handling, replacements iteration, etc.).
Reduce cyclomatic complexity below the flake8/mccabe threshold.
Add or update unit tests to cover the extracted functionality.
Benefits:
Improves readability and maintainability.
Easier testing of individual parts.
Aligns with Python style guidelines and helps keep CI checks green.