From 9fb87a74ce5400838e91fbe48c1d1c3493fe5583 Mon Sep 17 00:00:00 2001 From: david Date: Wed, 30 Oct 2024 00:05:18 +0100 Subject: [PATCH] Add loxecute feature --- bin/loxecute | 56 ++++++++++++++++++++++++++++++++++++++++++++ bin/railsn | 3 +++ config/generation.sh | 16 +++++++++++++ 3 files changed, 75 insertions(+) create mode 100755 bin/loxecute create mode 100755 bin/railsn create mode 100644 config/generation.sh diff --git a/bin/loxecute b/bin/loxecute new file mode 100755 index 0000000..0eb9429 --- /dev/null +++ b/bin/loxecute @@ -0,0 +1,56 @@ +#!/usr/bin/env bash + +set -eo pipefail + +# SYNTAX: +# catch STDOUT_VARIABLE STDERR_VARIABLE COMMAND [ARG1[ ARG2[ ...[ ARGN]]]] +catch() { + { + IFS=$'\n' read -r -d '' "${1}"; + IFS=$'\n' read -r -d '' "${2}"; + (IFS=$'\n' read -r -d '' _ERRNO_; return ${_ERRNO_}); + } < <((printf '\0%s\0%d\0' "$(((({ shift 2; "${@}"; echo "${?}" 1>&3-; } | tr -d '\0' 1>&4-) 4>&2- 2>&1- | tr -d '\0' 1>&4-) 3>&1- | exit "$(cat)") 4>&1-)" "${?}" 1>&2) 2>&1) +} +# " This line fixes my syntax highlighting + +# Only log rails generator commands (for now) +should_log() { + cmd=$(basename ${1}) + if [ "${cmd}" == "rails" ];then + case ${2} in + g | generate | d | delete) + echo 0 + ;; + *) + echo 1 + ;; + esac + else + echo 1 + fi +} + +# Execute catching output and error seperately +catch output errors "$@" +exit_code=$? + +# Show the command's output +cat <<< ${output} + +if [ ${exit_code} -eq 0 ] && [ -z "${errors}" ];then + # Was the command interesting? + log_it=$(should_log $@) + if [ ${log_it} -eq 0 ]; then + # Log date, command and output + comment="# $(date)" + msg="$@" + printf "${comment}\n${msg}\n" >> /app/config/generation.sh + cat <<< "${output}" | sed -e 's/^#*/# /' >> /app/config/generation.sh + fi +else + # Show the error. + # TODO: Ask user if the command should be stored anyways + echo "The command exited with \"${exit_code}\" wrote the following to STDERR:" + cat <<< "${errors}" +fi + diff --git a/bin/railsn b/bin/railsn new file mode 100755 index 0000000..0705a04 --- /dev/null +++ b/bin/railsn @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +exec loxecute rails "$@" \ No newline at end of file diff --git a/config/generation.sh b/config/generation.sh new file mode 100644 index 0000000..f175d8f --- /dev/null +++ b/config/generation.sh @@ -0,0 +1,16 @@ +# Wed Oct 30 00:03:55 CET 2024 +rails g model sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasd + invoke active_record + create db/migrate/20241029230355_create_sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasds.rb + create app/models/sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasd.rb + invoke test_unit + create test/models/sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasd_test.rb + create test/fixtures/sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasds.yml +# Wed Oct 30 00:04:14 CET 2024 +rails g model sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasddf +# invoke active_record +# create db/migrate/20241029230414_create_sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasddfs.rb +# create app/models/sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasddf.rb +# invoke test_unit +# create test/models/sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasddf_test.rb +# create test/fixtures/sdfsdlfkjdfsfsdfsfddsfsdfdsfsdflkjdsfjefdfsdssadasddfs.yml