From f4b77f30a3fddce4947c527cbdd05b585c3b159e Mon Sep 17 00:00:00 2001 From: Jaromil Date: Sun, 12 Nov 2023 22:24:55 +0100 Subject: [PATCH] breakroom auto mode re-run on any zencode modification --- src/breakroom/breakroom | 26 ++++++++++++++++++++++++++ src/breakroom/main.c | 2 ++ 2 files changed, 28 insertions(+) mode change 100644 => 100755 src/breakroom/breakroom diff --git a/src/breakroom/breakroom b/src/breakroom/breakroom old mode 100644 new mode 100755 index 5164fa3..ece2d27 --- a/src/breakroom/breakroom +++ b/src/breakroom/breakroom @@ -50,6 +50,7 @@ keys=0 data=0 extra=0 break=0 +onfail="trace" EOF } if ! [ -r $bconf ]; then @@ -93,6 +94,7 @@ if [ "$1" = "-h" ]; then _message " trace 🧭 show the backtrace of current execution" _message " heap 💾 show the HEAP of current execution" _message " codec 🗃️ show the CODEC of Given scope execution" + _message " auto ♻️ onitor zencode and re-run on modifications" _message " script [file] ⚡ get/set the zencode script file" _message " data [file] 🔡 get/set the data JSON input file" _message " keys [file] 🔢 get/set the keys JSON input file" @@ -159,13 +161,20 @@ _execute() { if [ $? = 0 ]; then cat breakroom.exec.stdout | jq . _success "Execution succesful" + return 0 else cat breakroom.exec.stderr | grep -v "^\"J64" _error "Failed execution" _getJ64 "TRACE" + return 1 fi } +if [ "$1" = "run" ]; then + _execute + exit $? +fi + tcmd=`mktemp` while true; do # read command from prompt @@ -216,6 +225,23 @@ while true; do codec|schema|given) _execute "scope=given" ;; + auto) + if ! command -v inotifywait; then + _error "Cannot find inotify-tools for auto mode" + continue + fi + tscript="$script"; [ $tscript = 0 ] && tscript="" + tdata="$data"; [ $tdata = 0 ] && tdata="" + tkeys="$keys"; [ $tkeys = 0 ] && tkeys="" + textra="$extra"; [ $textra = 0 ] && textra="" + while true; do + _success "AUTO mode: autorun on zencode changes" + inotifywait -q \ + -e modify \ + "${tscript}" "${tdata}" "${tkeys}" "${textra}" + _execute + done + ;; esac else # SET diff --git a/src/breakroom/main.c b/src/breakroom/main.c index 0c844b4..1bcba18 100644 --- a/src/breakroom/main.c +++ b/src/breakroom/main.c @@ -124,6 +124,8 @@ int main(int argc, char **argv) { CMD("trace"); CMD("bt"); CMD("heap"); CMD("codec"); CMD("schema"); CMD("given"); + CMD("auto"); + CMD("onfail"); fprintf(stdout,"Unknown command: %s\n", line); free(line); }