"""Module to run asteex runpackage as a script."""

from asteex.core.executor.executable import ExecutableExecutor
from asteex.core.runner import Runner
from asteex.runpackage.default import get_value_storage, get_fixture_storage, get_case_storage
from asteex.runpackage.generator import RunPackageGenerator

from asteex.runpackage.cli import (
    configure_logging,
    load_modules,
    prepare_reporter,
    create_parser,
)


parser = create_parser()
arguments = parser.parse_args()

configure_logging(config_path=arguments.logging_config_path)

# We import all modules from the package to make sure all storages are filled.
load_modules(package=arguments.package)

generator = RunPackageGenerator(
    root=arguments.package,
    value_storage=get_value_storage(),
    fixture_storage=get_fixture_storage(),
    case_storage=get_case_storage(),
)
executor = ExecutableExecutor()

reporter = prepare_reporter(
    entry_point_names=arguments.reporters_entry_point_names,
    import_paths=arguments.reporters_import_paths,
    config_paths=arguments.reporters_config_paths,
)

runner = Runner(generator=generator, executor=executor, reporter=reporter)

runner.run()
