"""
Unit tests for command-line interface.
"""

import pytest
from pathlib import Path
import subprocess
import sys
from fmusvid.cli.main import main

def test_cli_info(sample_video, capsys):
    """Test info command."""
    sys.argv = ["fmusvid", "info", str(sample_video)]
    main()
    captured = capsys.readouterr()
    assert "Video Information" in captured.out
    assert str(sample_video) in captured.out

def test_cli_convert(sample_video, temp_dir):
    """Test convert command."""
    output = temp_dir / "output.mp4"
    sys.argv = [
        "fmusvid",
        "convert",
        str(sample_video),
        str(output),
        "--codec",
        "h264"
    ]
    main()
    assert output.exists()

def test_cli_trim(sample_video, temp_dir):
    """Test trim command."""
    output = temp_dir / "trimmed.mp4"
    sys.argv = [
        "fmusvid",
        "trim",
        str(sample_video),
        str(output),
        "--start",
        "1.0",
        "--end",
        "3.0"
    ]
    main()
    assert output.exists()

def test_cli_invalid_command():
    """Test handling of invalid commands."""
    sys.argv = ["fmusvid", "invalid"]
    with pytest.raises(SystemExit):
        main()

def test_cli_missing_args():
    """Test handling of missing arguments."""
    sys.argv = ["fmusvid", "convert"]
    with pytest.raises(SystemExit):
        main()
