-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev.sh
More file actions
executable file
·85 lines (68 loc) · 1.62 KB
/
dev.sh
File metadata and controls
executable file
·85 lines (68 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
COMMAND=$1
CLASS_PATH=$2
if [[ "$COMMAND" != "make:class" ]]; then
echo "Invalid command. Use: ./dev.sh make:class ClassName or ./dev.sh make:class Lib/ClassName"
exit 1
fi
if [[ -z "$CLASS_PATH" ]]; then
echo "Error: No class name provided."
exit 1
fi
# Extract directory and class name
dir="$(dirname "$CLASS_PATH")"
classname="$(basename "$CLASS_PATH")"
namespace_name="$(echo "$dir" | sed 's#/#::#g')"
# Ensure the class is inside a subdirectory
if [[ "$dir" == "." ]]; then
echo "Error: Class must be inside a subdirectory."
exit 1
fi
# Define paths
SRC_DIR="src/$dir"
INCLUDE_DIR="include/$dir"
CPP_FILE="$SRC_DIR/$classname.cpp"
HEADER_FILE="$INCLUDE_DIR/$classname.h"
# Create directories if they don't exist
mkdir -p "$SRC_DIR"
mkdir -p "$INCLUDE_DIR"
# Create header file
if [[ ! -f "$HEADER_FILE" ]]; then
cat > "$HEADER_FILE" <<EOF
#ifndef ${classname^^}_H
#define ${classname^^}_H
namespace $namespace_name
{
class $classname
{
public:
$classname();
~${classname}();
};
} // namespace $namespace_name
#endif // ${classname^^}_H
EOF
echo "Created: $HEADER_FILE"
else
echo "Header file already exists: $HEADER_FILE"
fi
# Create source file
if [[ ! -f "$CPP_FILE" ]]; then
cat > "$CPP_FILE" <<EOF
#include "$classname.h"
namespace $namespace_name
{
$classname::$classname()
{
// Constructor implementation
}
$classname::~${classname}()
{
// Destructor implementation
}
} // namespace $namespace_name
EOF
echo "Created: $CPP_FILE"
else
echo "Source file already exists: $CPP_FILE"
fi