TR2X/tools/generate_init
2024-04-30 11:01:52 +02:00

38 lines
813 B
Python
Executable File

#!/usr/bin/env python3
import argparse
from pathlib import Path
from libtrx.versioning import generate_version
TEMPLATE = """
const char *g_TR2XVersion = "TR2X {version}";
""".lstrip()
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser()
parser.add_argument("-o", "--output", type=Path)
return parser.parse_args()
def get_init_c() -> str:
return TEMPLATE.format(version=generate_version())
def update_init_c(output_path: Path) -> None:
new_text = get_init_c()
if not output_path.exists() or output_path.read_text() != new_text:
output_path.write_text(new_text)
def main() -> None:
args = parse_args()
if args.output:
update_init_c(output_path=args.output)
else:
print(args.outptu)
if __name__ == "__main__":
main()