diff options
author | Leah Rowe <leah@libreboot.org> | 2023-05-18 10:41:30 +0100 |
---|---|---|
committer | Leah Rowe <leah@libreboot.org> | 2023-05-18 10:49:47 +0100 |
commit | 34df727c989d78430e5968fc6aeba7a5a108130a (patch) | |
tree | 6204d1803a86a049c3e0469441e6329c941c7aeb /build | |
parent | 1a062bb62810ba555351a01bb17f74e3beb992a8 (diff) |
build: cleaner coding style
main() on top
top-down logic
reduced indentation
Signed-off-by: Leah Rowe <leah@libreboot.org>
Diffstat (limited to 'build')
-rwxr-xr-x | build | 123 |
1 files changed, 65 insertions, 58 deletions
@@ -20,29 +20,73 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # -./.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 <MODE> <OPTION> @@ -58,54 +102,17 @@ help() { EOF } -die() { - printf 'Error: %s\n' "${@}" 1>&2 - exit 1 +listmodes() +{ + for mode in "${build}"/*; do + printf '%s\n' ${mode##*/} + done } -if [ $# -lt 1 ]; then - die "Wrong argument count. Run: ./build help" -fi - -mode="${1}" - -if [ "${mode}" != "dependencies" ]; then - ./resources/scripts/misc/versioncheck -fi - -[ "${mode}" = help ] && help && exit 0 - -if [ $# -gt 1 ]; then - - 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 - help - die "Invalid mode '${mode}'. Run: ./build help" - fi - if [ -f "${build}"/"${mode}"/"${option}" ]; then - "${build}"/"${mode}"/"${option}" $@ - else - help - printf "Invalid option for '%s'." ${mode} - die "Run: ./build ${mode} list'." - fi - esac -else - help - exit 0 -fi +die() +{ + printf 'Error: %s\n' ${@} 1>&2 + exit 1 +} -./.gitcheck clean +main $@ |