From 34df727c989d78430e5968fc6aeba7a5a108130a Mon Sep 17 00:00:00 2001 From: Leah Rowe Date: Thu, 18 May 2023 10:41:30 +0100 Subject: build: cleaner coding style main() on top top-down logic reduced indentation Signed-off-by: Leah Rowe --- build | 123 +++++++++++++++++++++++++++++++++++------------------------------- 1 file changed, 65 insertions(+), 58 deletions(-) (limited to 'build') diff --git a/build b/build index 1eb39216..4e1689a0 100755 --- a/build +++ b/build @@ -20,29 +20,73 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . # -./.gitcheck [ "x${DEBUG+set}" = 'xset' ] && set -v set -u -e projectname="$(cat projectname)" - build=./resources/scripts/build +mode="" +option="" + +main() +{ + if [ $# -lt 1 ]; then + die "Wrong argument count. Run: ./build help" + fi + mode="${1}" + + ./.gitcheck + + if [ "${mode}" != "dependencies" ]; then + ./resources/scripts/misc/versioncheck + fi + if [ "${mode}" = help ]; then + usage + exit 0 + elif [ $# -lt 2 ]; then + usage + exit 0 + fi -listmodes() { - for mode in "${build}"/*; do - printf '%s\n' "${mode##*/}" - done + option="${2}" + shift 2 + + case "${option}" in + list) + printf "Options for mode '%s':\n\n" ${mode} + listoptions "${mode}" + ;; + all) + for option in $(listoptions "${mode}"); do + "${build}/${mode}/${option}" $@ + done + ;; + *) + if [ ! -d "${build}/${mode}" ]; then + usage + die "Invalid mode '${mode}'. Run: ./build help" + elif [ ! -f "${build}/${mode}/${option}" ]; then + usage + printf "Invalid option for '%s'." ${mode} + die "Run: ./build ${mode} list'." + fi + "${build}/${mode}/${option}" $@ + esac + + ./.gitcheck clean } # Takes exactly one mode as parameter -listoptions() { - for option in "${build}"/"${1}"/*; do - printf '%s\n' "${option##*/}" +listoptions() +{ + for option in "${build}/${1}/"*; do + printf '%s\n' ${option##*/} done } -help() { +usage() +{ cat <<- EOF USAGE: ./build