This commit is contained in:
@@ -1,3 +1,18 @@
|
||||
"""
|
||||
# CLI Layer
|
||||
|
||||
The `docforge.cli` package provides the command-line interface for interacting
|
||||
with doc-forge.
|
||||
|
||||
## Available Commands
|
||||
|
||||
- **tree**: Visualize the introspected project structure.
|
||||
- **generate**: Create Markdown source files from Python code.
|
||||
- **mkdocs**: Generate the primary `mkdocs.yml` configuration.
|
||||
- **build**: Build the final documentation site.
|
||||
- **serve**: Launch a local development server with live-reloading.
|
||||
"""
|
||||
|
||||
from .main import main
|
||||
|
||||
__all__ = [
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
Main entry point for the doc-forge CLI. This module defines the core command
|
||||
group and the 'tree', 'generate', 'build', and 'serve' commands.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Sequence, Optional
|
||||
|
||||
@@ -10,7 +15,10 @@ from docforge.cli.mkdocs import mkdocs_cmd
|
||||
|
||||
@click.group()
|
||||
def cli() -> None:
|
||||
"""doc-forge command-line interface."""
|
||||
"""
|
||||
doc-forge CLI: A tool for introspecting Python projects and generating
|
||||
documentation.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@@ -35,7 +43,13 @@ def tree(
|
||||
modules: Sequence[str],
|
||||
project_name: Optional[str],
|
||||
) -> None:
|
||||
"""Show introspection tree."""
|
||||
"""
|
||||
Visualize the project structure including modules and their members.
|
||||
|
||||
Args:
|
||||
modules: List of module paths to introspect.
|
||||
project_name: Optional project name override.
|
||||
"""
|
||||
loader = GriffeLoader()
|
||||
project = loader.load_project(list(modules), project_name)
|
||||
|
||||
@@ -49,6 +63,9 @@ def tree(
|
||||
|
||||
|
||||
def _print_object(obj, indent: str) -> None:
|
||||
"""
|
||||
Recursive helper to print doc objects.
|
||||
"""
|
||||
click.echo(f"{indent}├── {obj.name}")
|
||||
for member in obj.get_all_members():
|
||||
_print_object(member, indent + "│ ")
|
||||
@@ -78,7 +95,14 @@ def generate(
|
||||
project_name: Optional[str],
|
||||
docs_dir: Path,
|
||||
) -> None:
|
||||
"""Generate documentation source files using MkDocs renderer."""
|
||||
"""
|
||||
Generate Markdown source files for the specified module.
|
||||
|
||||
Args:
|
||||
module: The primary module path to document.
|
||||
project_name: Optional project name override.
|
||||
docs_dir: Directory where documentation sources will be written.
|
||||
"""
|
||||
loader = GriffeLoader()
|
||||
discovered_paths = discover_module_paths(
|
||||
module,
|
||||
@@ -105,7 +129,12 @@ def generate(
|
||||
default=Path("mkdocs.yml"),
|
||||
)
|
||||
def build(mkdocs_yml: Path) -> None:
|
||||
"""Build documentation using MkDocs."""
|
||||
"""
|
||||
Build the documentation site using MkDocs.
|
||||
|
||||
Args:
|
||||
mkdocs_yml: Path to the mkdocs.yml configuration file.
|
||||
"""
|
||||
if not mkdocs_yml.exists():
|
||||
raise click.ClickException(f"mkdocs.yml not found: {mkdocs_yml}")
|
||||
|
||||
@@ -128,7 +157,12 @@ def build(mkdocs_yml: Path) -> None:
|
||||
default=Path("mkdocs.yml"),
|
||||
)
|
||||
def serve(mkdocs_yml: Path) -> None:
|
||||
"""Serve documentation using MkDocs."""
|
||||
"""
|
||||
Serve the documentation site with live-reload using MkDocs.
|
||||
|
||||
Args:
|
||||
mkdocs_yml: Path to the mkdocs.yml configuration file.
|
||||
"""
|
||||
if not mkdocs_yml.exists():
|
||||
raise click.ClickException(f"mkdocs.yml not found: {mkdocs_yml}")
|
||||
|
||||
@@ -147,6 +181,9 @@ def serve(mkdocs_yml: Path) -> None:
|
||||
# ---------------------------------------------------------------------
|
||||
|
||||
def main() -> None:
|
||||
"""
|
||||
CLI Entry point.
|
||||
"""
|
||||
cli()
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
"""
|
||||
This module contains the 'mkdocs' CLI command, which orchestrates the generation
|
||||
of the main mkdocs.yml configuration file.
|
||||
"""
|
||||
|
||||
from pathlib import Path
|
||||
from importlib import resources
|
||||
|
||||
@@ -10,6 +15,16 @@ from docforge.nav import MkDocsNavEmitter
|
||||
|
||||
|
||||
def _load_template(template: Path | None) -> dict:
|
||||
"""
|
||||
Load a YAML template for mkdocs.yml. If no template is provided,
|
||||
loads the built-in sample template.
|
||||
|
||||
Args:
|
||||
template: Path to the template file, or None.
|
||||
|
||||
Returns:
|
||||
The loaded template data as a dictionary.
|
||||
"""
|
||||
if template is not None:
|
||||
if not template.exists():
|
||||
raise click.FileError(str(template), hint="Template not found")
|
||||
@@ -59,7 +74,17 @@ def mkdocs_cmd(
|
||||
out: Path,
|
||||
site_name: str,
|
||||
) -> None:
|
||||
"""Generate mkdocs.yml from nav spec and template."""
|
||||
"""
|
||||
Generate an mkdocs.yml configuration file by combining a template with
|
||||
the navigation structure resolved from a docforge.nav.yml file.
|
||||
|
||||
Args:
|
||||
docs_dir: Path to the directory containing documentation Markdown files.
|
||||
nav_file: Path to the docforge.nav.yml specification.
|
||||
template: Optional path to an mkdocs.yml template.
|
||||
out: Path where the final mkdocs.yml will be written.
|
||||
site_name: The name of the documentation site.
|
||||
"""
|
||||
|
||||
if not nav_file.exists():
|
||||
raise click.FileError(str(nav_file), hint="Nav spec not found")
|
||||
|
||||
Reference in New Issue
Block a user