diff --git a/.code2promptrc b/.code2promptrc index 02ca85b..5de6b92 100644 --- a/.code2promptrc +++ b/.code2promptrc @@ -1,5 +1,4 @@ { - "path": "code2prompt", "suppress_comments": false, "line_number": false } \ No newline at end of file diff --git a/code2prompt/main.py b/code2prompt/main.py index 2a611d6..26de425 100644 --- a/code2prompt/main.py +++ b/code2prompt/main.py @@ -4,10 +4,10 @@ from code2prompt.core.process_files import process_files from code2prompt.core.write_output import write_output from code2prompt.utils.create_template_directory import create_templates_directory -from code2prompt.utils.logging_utils import log_token_count +from code2prompt.utils.logging_utils import log_token_count, log_error from code2prompt.utils.config import load_config, merge_options -VERSION = "0.6.4" # Define the version of the CLI tool +VERSION = "0.6.5" # Define the version of the CLI tool DEFAULT_OPTIONS = { "path": [], @@ -34,7 +34,6 @@ "--path", "-p", type=click.Path(exists=True), - required=True, multiple=True, # Allow multiple paths help="Path(s) to the directory or file to process.", ) @@ -122,21 +121,20 @@ def create_markdown_file(**cli_options): ## Load configuration from .code2promptrc files config = load_config(".") - - print(config) - # Merge options: CLI takes precedence over config, which takes precedence over defaults - # Merge options: CLI takes precedence over config, which takes precedence over defaults options = merge_options(cli_options, config, DEFAULT_OPTIONS) - - - print(options) if options["create_templates"]: create_templates_directory() return + if not options["path"]: + log_error( + "Error: No path specified. Please provide a path using --path option or in .code2promptrc file." + ) + return + all_files_data = [] for path in options["path"]: files_data = process_files({**options, "path": path}) diff --git a/code2prompt/utils/config.py b/code2prompt/utils/config.py index 7858f4e..59356b2 100644 --- a/code2prompt/utils/config.py +++ b/code2prompt/utils/config.py @@ -10,16 +10,17 @@ def load_config(current_dir): config = {} current_path = Path(current_dir).resolve() home_path = Path.home() - while current_path >= home_path: rc_file = current_path / '.code2promptrc' if rc_file.is_file(): with open(rc_file, 'r', encoding='utf-8') as f: - config.update(json.load(f)) + file_config = json.load(f) + if 'path' in file_config and isinstance(file_config['path'], str): + file_config['path'] = file_config['path'].split(',') + config.update(file_config) if current_path == home_path: break current_path = current_path.parent - return config def merge_options(cli_options: dict, config_options: dict, default_options: dict) -> dict: @@ -44,4 +45,8 @@ def merge_options(cli_options: dict, config_options: dict, default_options: dict else: merged[key] = value + # Special handling for 'path' + if not merged['path'] and 'path' in config_options: + merged['path'] = config_options['path'] + return merged \ No newline at end of file diff --git a/code2prompt/utils/logging_utils.py b/code2prompt/utils/logging_utils.py index 2c6b646..3609a4d 100644 --- a/code2prompt/utils/logging_utils.py +++ b/code2prompt/utils/logging_utils.py @@ -162,15 +162,66 @@ def log_success(message): logger.info(f"{Fore.GREEN}✅ SUCCESS: {message}{Style.RESET_ALL}") def log_file_processed(file_path): + """ + Logs a message indicating that a file has been processed. + + This function logs a message at the INFO level, indicating that a specific file has been processed. + It uses a blue color and a file emoji for visual distinction. + + Args: + file_path (str): The path to the file that was processed. + + Example: + log_file_processed("/path/to/file.txt") + """ logger.info(f"{Fore.BLUE}📄 Processed: {file_path}{Style.RESET_ALL}") def log_token_count(count): + """ + Logs the total number of tokens processed. + + This function logs the total count of tokens processed by the application, + using a cyan color and a token emoji for visual distinction. + + Args: + count (int): The total number of tokens processed. + + Example: + log_token_count(5000) + """ logger.info(f"{Fore.CYAN}🔢 Token count: {count}{Style.RESET_ALL}") def log_output_created(output_path): + """ + Logs a message indicating that an output file has been created. + + This function logs a message at the INFO level, indicating that an output file has been successfully created. + It uses a green color and a folder emoji for visual distinction. + + Args: + output_path (str): The path to the output file that was created. + + Example: + log_output_created("/path/to/output/file.txt") + """ logger.info(f"{Fore.GREEN}📁 Output file created: {output_path}{Style.RESET_ALL}") def log_clipboard_copy(success=True): + """ + Logs whether the content was successfully copied to the clipboard. + + This function logs a message indicating whether the content copying to the clipboard was successful or not. + It uses different emojis and colors depending on the success status. + + Args: + success (bool): Indicates whether the content was successfully copied to the clipboard. Defaults to True. + + Examples: + log_clipboard_copy(True) + Logs: 📋 Content copied to clipboard + log_clipboard_copy(False) + Logs: 📋 Failed to copy content to clipboard + """ if success: logger.info(f"{Fore.GREEN}📋 Content copied to clipboard{Style.RESET_ALL}") else: diff --git a/pyproject.toml b/pyproject.toml index 6fce788..d4f7b8a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "code2prompt" -version = "0.6.4" +version = "0.6.5" description = "A tool to convert code snippets into AI prompts for documentation or explanation purposes." authors = ["Raphael MANSUY "] license = "MIT"