import sys
import glob
import os

# Add the build directory to the Python path
build_paths = glob.glob("debian/python3-cyclopts/usr/lib/python3*/dist-packages")
for path in build_paths:
    sys.path.insert(0, os.path.abspath(path))

from cyclopts.cli import app
from cyclopts.completion.bash import generate_completion_script as bash_gen
from cyclopts.completion.zsh import generate_completion_script as zsh_gen
from cyclopts.completion.fish import generate_completion_script as fish_gen
from pathlib import Path

base = Path("debian/python3-cyclopts/usr/share")
files = {
    base / "bash-completion/completions/cyclopts": bash_gen(app, "cyclopts"),
    base / "zsh/vendor-completions/_cyclopts": zsh_gen(app, "cyclopts"),
    base / "fish/vendor_completions.d/cyclopts.fish": fish_gen(app, "cyclopts"),
}
for path, content in files.items():
    path.parent.mkdir(parents=True, exist_ok=True)
    path.write_text(content)
