Files
dl-organizer/src/vlm/cli.py
T

89 lines
2.8 KiB
Python
Raw Normal View History

2026-02-09 17:43:35 +08:00
"""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
2026-02-09 17:43:35 +08:00
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
2026-04-02 11:31:49 +08:00
2026-02-09 17:43:35 +08:00
@click.group()
@click.option(
'--config',
type=click.Path(path_type=Path),
default=default_config_path,
2026-02-09 17:43:35 +08:00
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.
2026-02-09 17:43:35 +08:00
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.
2026-02-09 17:43:35 +08:00
Common workflow:
2026-02-09 17:43:35 +08:00
1. vlm scan - Discover all video files
2. vlm parse - Extract titles, years, seasons, episodes
2026-04-02 11:31:49 +08:00
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
2026-02-09 17:43:35 +08:00
Use 'vlm COMMAND --help' for more information on a specific command.
"""
ctx.ensure_object(dict)
2026-02-09 17:43:35 +08:00
try:
ctx.obj = initialize_cli_context(config, log_level)
2026-02-09 17:43:35 +08:00
except Exception as e:
traceback.print_exc(file=sys.stderr)
2026-02-09 17:43:35 +08:00
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)
2026-02-09 17:43:35 +08:00
if __name__ == '__main__':
main()