From 4c352f642c7297cc8d1a9f96202b88178564d1b0 Mon Sep 17 00:00:00 2001 From: Lucie Scarlet Date: Fri, 26 Jul 2024 10:47:11 +0200 Subject: [PATCH] [cmakegen] Made invalid flags error out Instead of creating a C++ project when you misset argv[1], eg. `cmakegen 0c` instead of `cmakegen -c`. Also made it easier to add other flags in the future. Might clean it up more though. --- cmakegen | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmakegen b/cmakegen index 9cd750d..f6a0c99 100755 --- a/cmakegen +++ b/cmakegen @@ -6,11 +6,20 @@ from sys import argv CMAKE_TEMPLATE = dirname(__file__) + "/CMakeLists.txt.tmpl" CMAKE_C_TEMPLATE = dirname(__file__) + "/CMakeLists.txt.ctmpl" CMAKE_FILE = getcwd() + "/CMakeLists.txt" +C_FLAGS: tuple = ("-c",) +CPP_FLAGS: tuple = ("-cpp", "-c++", "-cc") def main() -> int: cmake_contents: str project_name : str = getcwd().split("/")[-1] - is_c: bool = True if len(argv) > 1 and argv[1] in ("-c",) else False + is_c: bool = False + if len(argv) > 1: + if argv[1] in C_FLAGS and not argv[1] in CPP_FLAGS: + is_c = True + elif argv[1] in CPP_FLAGS and not argv[1] in C_FLAGS: + is_c = False + else: + raise SyntaxError(f"Option {argv[1]} not recognized.") template = CMAKE_C_TEMPLATE if is_c else CMAKE_TEMPLATE with open(template, "r") as f: cmake_contents = f.read() -- 2.45.2