import argparse
import asyncio
import logging
import os

from tts_client.tts_protocol import tts_query
from tts_lua.yarn_installer import yarn_check_install


def _get_argparser():
    parser = argparse.ArgumentParser(description="Tabletop Simulator Dev server")
    parser.add_argument(
        "--output-dir",
        type=str,
        help="The output path for autogenerated files what will be consumed when sending files",
        required=True,
    )
    parser.add_argument(
        "--command",
        type=str,
        choices=("push", "pull", "soft_push"),
        help="Command to perform",
        required=True,
    )
    parser.add_argument(
        "--dont-check-yarn",
        type=bool,
        help="Don't check yarn package version at startup",
        default=True,
        required=False,
    )
    parser.add_argument(
        "--libdir", help="Path to search for ttslua libs", action="append"
    )

    parser.add_argument(
        "-v", "--verbose", help="increase output verbosity", action="store_true"
    )
    return parser


if __name__ == "__main__":
    parser = _get_argparser()
    args = parser.parse_args()
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    if args.output_dir:
        if not os.path.isdir(args.output_dir):
            raise ValueError(f"Directory {args.output_dir} doesn't exists")
    if not args.dont_check_yarn:
        yarn_check_install()

    asyncio.run(
        tts_query(args.command, export_dir=args.output_dir, lib_dirs=args.libdir)
    )

import argparse
import asyncio
import logging
import os

from tts_client.tts_protocol import tts_query
from tts_lua.yarn_installer import yarn_check_install


def _get_argparser():
    parser = argparse.ArgumentParser(description="Tabletop Simulator Dev server")
    parser.add_argument(
        "--output-dir",
        type=str,
        help="The output path for autogenerated files what will be consumed when sending files",
        required=True,
    )
    parser.add_argument(
        "--command",
        type=str,
        choices=("push", "pull", "soft_push"),
        help="Command to perform",
        required=True,
    )
    parser.add_argument(
        "--dont-check-yarn",
        type=bool,
        help="Don't check yarn package version at startup",
        default=True,
        required=False,
    )
    parser.add_argument(
        "--libdir", help="Path to search for ttslua libs", action="append"
    )

    parser.add_argument(
        "-v", "--verbose", help="increase output verbosity", action="store_true"
    )
    return parser


if __name__ == "__main__":
    parser = _get_argparser()
    args = parser.parse_args()
    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)

    if args.output_dir:
        if not os.path.isdir(args.output_dir):
            raise ValueError(f"Directory {args.output_dir} doesn't exists")
    if not args.dont_check_yarn:
        yarn_check_install()

    asyncio.run(
        tts_query(args.command, export_dir=args.output_dir, lib_dirs=args.libdir)
    )
