Spaces:
Sleeping
Sleeping
| import click | |
| from .config import load_config | |
| from .llm_handler import LLMHandler | |
| from .orchestrator import DocstringOrchestrator | |
| from .readme_generator import ReadmeGenerator | |
| def cli(ctx): | |
| """ | |
| CodeScribe AI: A tool for AI-assisted project documentation. | |
| Choose a command below (e.g., 'docstrings', 'readmes') and provide its options. | |
| """ | |
| # This parent command now only handles setup common to all subcommands. | |
| ctx.ensure_object(dict) | |
| try: | |
| config = load_config() | |
| if not config.api_keys: | |
| raise click.UsageError("No API keys found in the .env file. Please create one.") | |
| ctx.obj['LLM_HANDLER'] = LLMHandler(config.api_keys) | |
| click.echo(f"Initialized with {len(config.api_keys)} API keys.") | |
| except Exception as e: | |
| raise click.ClickException(f"Initialization failed: {e}") | |
| def docstrings(ctx, path, desc, exclude): | |
| """Generates Python docstrings for all files.""" | |
| click.echo("\n--- Starting Docstring Generation ---") | |
| llm_handler = ctx.obj['LLM_HANDLER'] | |
| orchestrator = DocstringOrchestrator( | |
| path_or_url=path, | |
| description=desc, | |
| exclude=list(exclude), | |
| llm_handler=llm_handler | |
| ) | |
| try: | |
| orchestrator.run() | |
| click.secho("Successfully generated all docstrings.", fg="green") | |
| except Exception as e: | |
| click.secho(f"An error occurred during docstring generation: {e}", fg="red") | |
| def readmes(ctx, path, desc, exclude): | |
| """Generates README.md files for each directory.""" | |
| click.echo("\n--- Starting README Generation ---") | |
| llm_handler = ctx.obj['LLM_HANDLER'] | |
| generator = ReadmeGenerator( | |
| path_or_url=path, | |
| description=desc, | |
| exclude=list(exclude), | |
| llm_handler=llm_handler | |
| ) | |
| try: | |
| generator.run() | |
| click.secho("Successfully generated all README files.", fg="green") | |
| except Exception as e: | |
| click.secho(f"An error occurred during README generation: {e}", fg="red") | |
| def main(): | |
| cli(obj={}) | |
| if __name__ == '__main__': | |
| main() |