import shutil
import subprocess
import sys
from pathlib import Path

import click


@click.command()
@click.option('--data_folder', default=None)
@click.option('--generate_pyqt', default=True)
@click.option('--dev/--no-dev', default=True)
def main(data_folder, generate_pyqt, dev):
    if dev:
        sys.argv.append('--dev')
    import flandre
    from flandre.launcher import launch_from_file
    from flandre.config import C

    if (pyuic6 := shutil.which('pyuic6')) is None:
        print('pyuic6 is not installed')
        return
    if generate_pyqt:
        subprocess.run([pyuic6, '-o', flandre.PYQT / 'Main.py', flandre.PYQT / 'Main.ui'])
        subprocess.run([pyuic6, '-o', flandre.PYQT / 'Image.py', flandre.PYQT / 'Image.ui'])
    if data_folder is not None:
        C.data_folder = Path(data_folder)

    launch_from_file(Path(__file__).parent / 'launch.toml')


if __name__ == '__main__':
    main()
