Add utils, templates, config, interactive, and github modules
This commit is contained in:
139
src/auto_readme/interactive/__init__.py
Normal file
139
src/auto_readme/interactive/__init__.py
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
"""Interactive wizard for customizing README content."""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
import click
|
||||||
|
|
||||||
|
from ..models import Project
|
||||||
|
|
||||||
|
|
||||||
|
class ProjectInfoWizard:
|
||||||
|
"""Wizard for collecting project information."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(project: Project) -> Project:
|
||||||
|
"""Run the project info wizard."""
|
||||||
|
if not project.config:
|
||||||
|
project.config.name = project.root_path.name
|
||||||
|
|
||||||
|
project.config.name = click.prompt(
|
||||||
|
"Project name",
|
||||||
|
default=project.config.name if project.config else project.root_path.name,
|
||||||
|
)
|
||||||
|
|
||||||
|
project.config.description = click.prompt(
|
||||||
|
"Project description",
|
||||||
|
default=project.config.description or "A project generated by auto-readme",
|
||||||
|
)
|
||||||
|
|
||||||
|
project.config.author = click.prompt(
|
||||||
|
"Author (optional)",
|
||||||
|
default=project.config.author or "",
|
||||||
|
show_default=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
project.config.email = click.prompt(
|
||||||
|
"Email (optional)",
|
||||||
|
default=project.config.email or "",
|
||||||
|
show_default=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
project.config.license = click.prompt(
|
||||||
|
"License (optional)",
|
||||||
|
default=project.config.license or "MIT",
|
||||||
|
show_default=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
return project
|
||||||
|
|
||||||
|
|
||||||
|
class SectionWizard:
|
||||||
|
"""Wizard for customizing README sections."""
|
||||||
|
|
||||||
|
SECTION_OPTIONS = [
|
||||||
|
("overview", "Project Overview"),
|
||||||
|
("installation", "Installation"),
|
||||||
|
("usage", "Usage"),
|
||||||
|
("features", "Features"),
|
||||||
|
("api", "API Reference"),
|
||||||
|
("contributing", "Contributing"),
|
||||||
|
("license", "License"),
|
||||||
|
]
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run() -> dict:
|
||||||
|
"""Run the section wizard."""
|
||||||
|
click.echo("\n=== Section Configuration ===")
|
||||||
|
click.echo("Select which sections to include in your README:\n")
|
||||||
|
|
||||||
|
sections = {}
|
||||||
|
for section_key, section_name in SectionWizard.SECTION_OPTIONS:
|
||||||
|
include = click.confirm(f"Include {section_name}?", default=True)
|
||||||
|
sections[section_key] = include
|
||||||
|
|
||||||
|
click.echo("\nSection order (default order used). You can reorder by editing the config file.")
|
||||||
|
return sections
|
||||||
|
|
||||||
|
|
||||||
|
class ContentWizard:
|
||||||
|
"""Wizard for manual overrides of auto-detected values."""
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def run(project: Project) -> Project:
|
||||||
|
"""Run the content wizard."""
|
||||||
|
click.echo("\n=== Content Customization ===")
|
||||||
|
click.echo("You can override any auto-detected values below. Leave blank to keep auto-detected values.\n")
|
||||||
|
|
||||||
|
project.installation_steps = ContentWizard._edit_list(
|
||||||
|
"installation steps",
|
||||||
|
project.installation_steps or ["pip install -e ."],
|
||||||
|
)
|
||||||
|
|
||||||
|
project.usage_examples = ContentWizard._edit_list(
|
||||||
|
"usage examples",
|
||||||
|
project.usage_examples or ["# See the docs"],
|
||||||
|
)
|
||||||
|
|
||||||
|
project.features = ContentWizard._edit_list(
|
||||||
|
"features",
|
||||||
|
project.features or [],
|
||||||
|
)
|
||||||
|
|
||||||
|
return project
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def _edit_list(prompt_name: str, current_list: list[str]) -> list[str]:
|
||||||
|
"""Edit a list of strings."""
|
||||||
|
click.echo(f"\nCurrent {prompt_name}:")
|
||||||
|
for i, item in enumerate(current_list, 1):
|
||||||
|
click.echo(f" {i}. {item}")
|
||||||
|
|
||||||
|
add_new = click.confirm(f"Add new {prompt_name}?", default=False)
|
||||||
|
if not add_new:
|
||||||
|
return current_list
|
||||||
|
|
||||||
|
new_list = current_list[:]
|
||||||
|
while True:
|
||||||
|
new_item = click.prompt(f" Enter {prompt_name} (or leave blank to finish)", default="", show_default=False)
|
||||||
|
if not new_item:
|
||||||
|
break
|
||||||
|
new_list.append(new_item)
|
||||||
|
|
||||||
|
return new_list if new_list else current_list
|
||||||
|
|
||||||
|
|
||||||
|
def run_wizard(project: Project) -> Project:
|
||||||
|
"""Run the complete interactive wizard."""
|
||||||
|
click.echo("=== Auto README Generator - Interactive Mode ===\n")
|
||||||
|
|
||||||
|
project = ProjectInfoWizard.run(project)
|
||||||
|
|
||||||
|
project.custom_sections["section_config"] = SectionWizard.run()
|
||||||
|
|
||||||
|
project = ContentWizard.run(project)
|
||||||
|
|
||||||
|
click.echo("\n=== Wizard Complete ===")
|
||||||
|
click.echo("Your README will be generated with the provided information.")
|
||||||
|
|
||||||
|
return project
|
||||||
Reference in New Issue
Block a user