Files
dl-organizer/src/vlm/cli.py
T
windyboyandClaude Sonnet 4.5 fe03a31dd4 refactor: DLO-16/17/18/20 — CLI simplification, config Pydantic, planner split, type system unification
DLO-16: Reduce cli.py from 1073 to 83 lines by registering Click commands from commands/*.py modules
DLO-17: Migrate Config to Pydantic BaseModel for validation
DLO-18: Split planner.py (826 lines) into orchestration, path rendering, and duplicate handling modules
DLO-20: Unify type system — convert 14 dataclasses to Pydantic BaseModel, keep TypedDicts as JSON schema hints

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-09-27 10:47:04 +08:00

89 lines
2.8 KiB
Python

"""Command-line interface for Video Library Manager.
This module provides the main CLI entry point using Click framework.
It implements global options (--config, --log-level) and error handling.
"""
import sys
import traceback
from pathlib import Path
from typing import Optional
import click
from vlm.cli_helpers import default_config_path, initialize_cli_context
from vlm.commands.analyze import analyze
from vlm.commands.config_cmd import config_group
from vlm.commands.enrich import enrich
from vlm.commands.execute import execute, rollback
from vlm.commands.parse import parse
from vlm.commands.plan import plan
from vlm.commands.quarantine_cmd import quarantine
from vlm.commands.report import report
from vlm.commands.review_plan import apply_review, review_plan
from vlm.commands.scan import scan
from vlm.commands.state_cmd import state
@click.group()
@click.option(
'--config',
type=click.Path(path_type=Path),
default=default_config_path,
help='Path to configuration file (default: ~/.vlm/config.yaml)'
)
@click.option(
'--log-level',
type=click.Choice(['DEBUG', 'INFO', 'WARNING', 'ERROR'], case_sensitive=False),
default=None,
help='Set logging level (overrides config file)'
)
@click.pass_context
def main(ctx, config: Path, log_level: Optional[str]):
"""Video Library Manager - A tool for managing personal video collections.
VLM helps you organize, analyze, and maintain your video library with a
safety-first approach. All operations are reversible and require explicit
confirmation before making changes.
Common workflow:
1. vlm scan - Discover all video files
2. vlm parse - Extract titles, years, seasons, episodes
3. vlm enrich - Enrich parsed identities with external metadata
4. vlm analyze - Detect gaps and duplicates
5. vlm plan - Generate execution plan
6. vlm execute - Execute plan (dry-run by default)
7. vlm execute --confirm - Actually execute operations
Use 'vlm COMMAND --help' for more information on a specific command.
"""
ctx.ensure_object(dict)
try:
ctx.obj = initialize_cli_context(config, log_level)
except Exception as e:
traceback.print_exc(file=sys.stderr)
click.echo(f"Error initializing VLM: {e}", err=True)
sys.exit(1)
# Register commands
main.add_command(analyze)
main.add_command(apply_review, name="apply-review")
main.add_command(config_group, name="config")
main.add_command(enrich)
main.add_command(execute)
main.add_command(parse)
main.add_command(plan)
main.add_command(quarantine)
main.add_command(report)
main.add_command(rollback)
main.add_command(review_plan, name="review-plan")
main.add_command(scan)
main.add_command(state)
if __name__ == '__main__':
main()