From b3282bfc6e62598ec637a7591f2d03dffab75d7a Mon Sep 17 00:00:00 2001 From: Kirill Markin Date: Sat, 8 Jun 2024 11:13:39 +0200 Subject: [PATCH] debug logging option --- README.md | 8 ++++++++ repo_to_text/main.py | 17 ++++++++++++----- requirements.txt | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8d95a5f..9f646ed 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,14 @@ repo-to-text This will create a file named `repo_structure.txt` in the current directory with the text representation of the repository. +## Enabling Debug Logging + +By default, repo-to-text runs with INFO logging level. To enable DEBUG logging, use the --debug flag: + +```bash +repo-to-text --debug +``` + ## Example Output The generated text file will include the directory structure and contents of each file. For example: diff --git a/repo_to_text/main.py b/repo_to_text/main.py index 4899dc6..5a35053 100644 --- a/repo_to_text/main.py +++ b/repo_to_text/main.py @@ -2,9 +2,11 @@ import os import subprocess import pathspec import logging +import argparse -# Configure logging -logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') +def setup_logging(debug=False): + logging_level = logging.DEBUG if debug else logging.INFO + logging.basicConfig(level=logging_level, format='%(asctime)s - %(levelname)s - %(message)s') def get_tree_structure(path='.', gitignore_spec=None) -> str: logging.debug(f'Generating tree structure for path: {path}') @@ -106,10 +108,15 @@ def save_repo_to_text(path='.') -> None: file.write('\n```\n') logging.debug('Repository contents written to file') -def main() -> None: +def main(): + parser = argparse.ArgumentParser(description='Convert repository structure and contents to text') + parser.add_argument('--debug', action='store_true', help='Enable debug logging') + args = parser.parse_args() + + setup_logging(debug=args.debug) + logging.debug('repo-to-text script started') save_repo_to_text() + logging.debug('repo-to-text script finished') if __name__ == '__main__': - logging.debug('repo-to-text script started') main() - logging.debug('repo-to-text script finished') diff --git a/requirements.txt b/requirements.txt index 7273639..e60962f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ setuptools==70.0.0 pathspec==0.12.1 +pytest==8.2.2 +argparse==1.4.0