import argparse
from pathlib import Path
from jinja2 import Template


if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description='A tool to dynamically build release pipelines')
    requiredNamed = parser.add_argument_group('Required named arguments')
    requiredNamed.add_argument("--job_id", required=True, help="build job ID required for links")
    requiredNamed.add_argument("--pipeline_id", required=True, help="build pipeline ID required for links")
    requiredNamed.add_argument("--tag", required=True, help="build tag required for file names etc.")
    args = parser.parse_args()

    file = Path(__file__).parent / "templates/release_pipeline.bat.jinja"
    file_out = Path(__file__).parent / "release_pipeline.bat"
    templated = Template(file.read_text())
    rendered = templated.render(
        version=args.tag,
        job_id=args.job_id,
        pipeline_id=args.pipeline_id,
        description=f"An automated release of Blade for tag {args.tag}",
    )
    file_out.write_text(rendered)
