refactor: restructure mytoolkit with new subcommands and md-to-pdf improvements
- Add new subcommands: convert, preflight, server, templates, webpage - Migrate config from bin/config.json to ~/.config/mytoolkit - Fix expand_bookmarks to modify writer objects instead of reader - Improve md_to_pdf with CJK bookmark support - Update README and project metadata
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"""Templates registry CLI."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import click
|
||||
|
||||
from bin import templates_registry
|
||||
|
||||
|
||||
@click.group(name="templates")
|
||||
def templates_cmd():
|
||||
"""Manage external templates registry."""
|
||||
pass
|
||||
|
||||
|
||||
@templates_cmd.command("register")
|
||||
@click.argument("path", type=click.Path(exists=True, file_okay=False, dir_okay=True))
|
||||
def templates_register(path):
|
||||
"""Register a directory as the templates root."""
|
||||
resolved = templates_registry.set_root(Path(path))
|
||||
click.secho(f"Registered: {resolved}", fg="green")
|
||||
|
||||
|
||||
@templates_cmd.command("show")
|
||||
def templates_show():
|
||||
"""Show the current registry and available templates."""
|
||||
if not templates_registry.CONFIG_PATH.exists():
|
||||
click.echo("No registry. Run: mytoolkit templates register <path>")
|
||||
return
|
||||
|
||||
import json
|
||||
|
||||
with open(templates_registry.CONFIG_PATH, encoding="utf-8") as f:
|
||||
data = json.load(f)
|
||||
raw = data.get("dir")
|
||||
click.echo(f"Registry: {templates_registry.CONFIG_PATH}")
|
||||
click.echo(f"Root: {raw}")
|
||||
|
||||
if not raw or not Path(raw).is_dir():
|
||||
click.secho("(root path missing)", fg="red")
|
||||
return
|
||||
|
||||
root = Path(raw)
|
||||
pdf_dir = root / "md-to-pdf"
|
||||
docx_dir = root / "md-to-docx"
|
||||
|
||||
click.echo("\nmd-to-pdf:")
|
||||
if pdf_dir.is_dir():
|
||||
entries = sorted(
|
||||
(p.name, p / "template.typ")
|
||||
for p in pdf_dir.iterdir()
|
||||
if (p / "template.typ").exists()
|
||||
)
|
||||
if not entries:
|
||||
click.echo(" (none)")
|
||||
else:
|
||||
width = max(len(n) for n, _ in entries)
|
||||
for name, path in entries:
|
||||
click.echo(f" - {name:<{width}} {path}")
|
||||
else:
|
||||
click.secho(" (subdirectory missing)", fg="yellow")
|
||||
|
||||
click.echo("\nmd-to-docx:")
|
||||
if docx_dir.is_dir():
|
||||
entries = sorted(
|
||||
(p.name, p / "template.docx")
|
||||
for p in docx_dir.iterdir()
|
||||
if (p / "template.docx").exists()
|
||||
)
|
||||
if not entries:
|
||||
click.echo(" (none)")
|
||||
else:
|
||||
width = max(len(n) for n, _ in entries)
|
||||
for name, path in entries:
|
||||
click.echo(f" - {name:<{width}} {path}")
|
||||
else:
|
||||
click.secho(" (subdirectory missing)", fg="yellow")
|
||||
Reference in New Issue
Block a user