-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.sh
executable file
·77 lines (63 loc) · 1.77 KB
/
init.sh
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
#!/usr/bin/env bash
makefile_project_name_marker="#ProjectNameMarker"
read -r -d '' header_content_template <<'EOF'
#ifndef NAMEOFUNIT_H
#define NAMEOFUNIT_H
#endif NAMEOFUNIT_H
EOF
read -r -d '' test_content_template <<'EOF'
#include <unity.h>
#include <NAMEOFUNIT.h>
void test_NAMEOFUNIT_firstTest(void) {
}
EOF
function create_module {
touch ./sources/$1.c
touch ./tests/$1-test.c
touch ./includes/$1.h
create_source_file $1
create_header_file $1
create_test_file $1
register_test_file $1
echo "Module named '$1' was created"
}
function create_source_file {
echo "#include \"$1.h\"" >> ./sources/$1.c
}
function create_header_file {
header_content=$(sed "s/NAMEOFUNIT/$1/g" <<< $header_content_template)
echo "${header_content^^}" >> ./includes/$1.h
}
function create_test_file {
test_content=$(sed "s/NAMEOFUNIT/$1/g" <<< $test_content_template)
echo "${test_content}" >> ./tests/$1-test.c
}
function register_test_file {
# TODO: Make this less hacky
echo "#include <$1-test.h>" >> ./tests/main-test.c
echo "extern void test_$1_firstTest(void);" >> ./tests/main-test.c
}
function additional_module_prompt {
read -p "One more module? [y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Module name?: " module_name
create_module $module_name
additional_module_prompt
else
echo "All done!"
exit 0
fi
}
if grep -qF "$makefile_project_name_marker" Makefile
then
read -p "Name of project: " project_name
sed -i "s/$makefile_project_name_marker/$project_name/g" Makefile
read -p "Name of first module?: " module_name
create_module $module_name
additional_module_prompt
else
echo "Project is already initialized"
additional_module_prompt
fi