]> Git repositories of Lucie Scarlet - cmakegen.git/commitdiff
[cmakegen] Made invalid flags error out
authorLucie Scarlet <lucie@scarlet.moe>
Fri, 26 Jul 2024 08:47:11 +0000 (10:47 +0200)
committerLucie Scarlet <lucie@scarlet.moe>
Fri, 26 Jul 2024 08:47:11 +0000 (10:47 +0200)
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

index 9cd750d398fc6b2cb5612766cf09ebc9b59ae351..f6a0c995a0d6bae3a731788e0d1728395ec8961c 100755 (executable)
--- 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()