-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp_project_setup.py
More file actions
63 lines (45 loc) · 1.62 KB
/
cpp_project_setup.py
File metadata and controls
63 lines (45 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
import argparse
import os
"""
function to create a directory if not already exists
"""
def create_directory(path):
if not os.path.exists(path):
os.makedirs(path)
print(f"created directory: {path}")
else:
print(f"Warning: Directory already exists: {path}")
"""
create new file with content
"""
def create_new_file(path, content=""):
if not os.path.exists(path):
with open(path, "w") as file:
file.write(content)
print(f"created new file: {path}")
else:
print(f"Warning: File already exists: {path}")
if __name__ == "__main__":
print("C++ Project Setup")
#create ArgumentParser object
parser = argparse.ArgumentParser()
#new Terminal arg -> project_name with flag: --help -> Project name
parser.add_argument("project_name", help="Project name")
# parse from parser object args to args object
args = parser.parse_args()
# example usage could be:
# print("This is the project name: " + args.project_name)
"""
Creating Project Structure
"""
# Define project root path
project_path = os.path.join(os.getcwd(), args.project_name)
create_directory(project_path)
# Create subdirectories
create_directory(os.path.join(project_path, "src"))
create_directory(os.path.join(project_path, "build"))
# Create files
create_new_file(os.path.join(project_path, "README.md"), f"# {args.project_name}\n")
create_new_file(os.path.join(project_path, "src", "main.cpp"),
'#include <iostream>\n\nint main() {\n // TODO Implement here\n return 0;\n}')