From a6aac1806c247907b51df6ba8c5def500f274321 Mon Sep 17 00:00:00 2001 From: TheUltimateOptimist Date: Sun, 28 Jan 2024 01:26:26 +0100 Subject: [PATCH] implemented addfile script --- addfile | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 addfile diff --git a/addfile b/addfile new file mode 100755 index 0000000..e94a39a --- /dev/null +++ b/addfile @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +if test ! -f "project.yml"; then + echo -e "no project.yml was found -> generation failed\nplease run this command from the root of the project directory" + exit 1 +fi +if test -z $1; then + echo "no file path was provided -> generation failed" + exit 1 +fi + +name="$(basename $1)" +mkdir -p "test/$(dirname $1)" +mkdir -p "src/$(dirname $1)" + +testcontent="#include \"unity.h\"\n#include \"$1.h\"\n\nvoid setUp(void){}\nvoid tearDown(void){}" +filecontent="#include \"$name.h\"" +headercontent="#ifndef ${name^^}_H\n#define ${name^^}_H\n\n\n#endif" + +if test -e "test/test_$1.c"; then + echo "the file test/test_$1.c already exists -> generation failed" + exit 1 +fi +if test -e "src/$1.c"; then + echo "the file src/$1.c already exists -> generation failed" + exit 1 +fi +if test -e "src/$1.h"; then + echo "the file src/$1.h already exists -> generation failed" + exit 1 +fi + +echo -e $testcontent > "test/test_$1.c" +echo -e $filecontent > "src/$1.c" +echo -e $headercontent > "src/$1.h" \ No newline at end of file