-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenclass
executable file
·67 lines (61 loc) · 1.85 KB
/
genclass
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
#!/bin/bash
display_help()
{
echo "Using 'genclass CppClass' will output two Orthodox Canonical classes named 'CppClass.cpp' and 'CppClass.hpp'."
echo "Using 'genclass' with no arguments will create a 'main.cpp' base."
echo "Using 'genclass --help' displays this message."
}
create_base_template()
{
EXEC_PATH=$(type -a genclass | cut -d" " -f3 | grep -i "^/" | sed -n '1p' | sed 's|\(.*\)/.*|\1|')
if ! test -f ./main.cpp; then
cat $EXEC_PATH/main_cpp_template > ./main.cpp
fi
echo "Base template created"
}
create_single_class()
{
EXEC_PATH=$(type -a genclass | cut -d" " -f3 | grep -i "^/" | sed -n '1p' | sed 's|\(.*\)/.*|\1|')
CLASS_NO_PATH=$(echo "$1" | rev | cut -d'/' -f1 | rev)
CLASS_PATH=$(echo "$1" | rev | cut -d'/' -f2- | rev)
if [ "$CLASS_PATH" == "$CLASS_NO_PATH" ]
then
CLASS_PATH="."
fi
CLASS_BASE_NAME=$(echo "$CLASS_NO_PATH" | sed 's/\(.*\)\.cpp$/\1/;s/\(.*\)\.hpp$/\1/')
if ! test -f $CLASS_PATH/$CLASS_BASE_NAME.cpp; then
cat $EXEC_PATH/class_cpp_template | sed "s/ClassName/$CLASS_BASE_NAME/g" | sed "s/Class.hpp/$CLASS_BASE_NAME.hpp/g" > $CLASS_PATH/$CLASS_BASE_NAME.cpp
if [ $? == 0 ]
then
echo "'$CLASS_PATH/$CLASS_BASE_NAME.cpp' created"
fi
else
echo "'$CLASS_PATH/$CLASS_BASE_NAME.cpp' already exists"
fi
if ! test -f $CLASS_PATH/$CLASS_BASE_NAME.hpp; then
cat $EXEC_PATH/class_hpp_template | sed "s/ClassName/$CLASS_BASE_NAME/g" | sed "s/CLASSNAME/${CLASS_BASE_NAME^^}/g" > $CLASS_PATH/$CLASS_BASE_NAME.hpp
if [ $? == 0 ]
then
echo "'$CLASS_PATH/$CLASS_BASE_NAME.hpp' created"
fi
else
echo "'$CLASS_PATH/$CLASS_BASE_NAME.hpp' already exists"
fi
}
if [ $# == 1 ]
then
if [ "$1" == "--help" ]
then
display_help
elif [ ${1:0:1} == "-" ]
then
echo "[GENCLASS] Unknown option $1"
else
create_single_class "$1"
fi
elif [ $# == 0 ]
then
create_base_template
else
echo "Invalid number of arguments."
fi