From bbbb80e53143e8f4b96b3ed1723a30dd334ed436 Mon Sep 17 00:00:00 2001 From: Rezart Qelibari Date: Mon, 7 Feb 2022 18:51:20 +0100 Subject: [PATCH] Add suffix module filtering and module search path --- install.sh | 31 ++++++++++++++++++------------- spec/filterModules_spec.sh | 8 ++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/install.sh b/install.sh index 454bb83..571ba1f 100755 --- a/install.sh +++ b/install.sh @@ -19,13 +19,14 @@ function filterModules() { if [ "${#module}" -eq 0 ]; then modulesToInstall=("${allModules[@]}") else - local mod + local mod pattern="^.*(${(j.|.)module})\$" modulesToInstall=() for mod in "${allModules[@]}"; do - local foundAtIndex="${module[(Ie)${mod}]}" - if [ "${inverse}" != 'true' -a "${foundAtIndex}" -gt 0 ]; then + local found=false + [[ "${mod}" =~ ${pattern} ]] && found=true + if [ "${inverse}" != 'true' -a "${found}" = true ]; then modulesToInstall+=("${mod}") - elif [ "${inverse}" = 'true' -a "${foundAtIndex}" -eq 0 ]; then + elif [ "${inverse}" = 'true' -a "${found}" = false ]; then modulesToInstall+=("${mod}") fi done @@ -159,28 +160,32 @@ function askNecessaryQuestions() { function printModulesToInstall() { hio info 'Modules that will install are:' for mod in "${modulesToInstall[@]}"; do - hio debug "${mod}" - done + echo "${mod}" + done | abbreviatePaths exit 0 } function loadModules() { - allModules=("${(f)$(find ./modules -type f -perm +u=x -maxdepth 1 2> /dev/null | awk -F/ '{print $NF }' | sort -n)}") + modpath=("${_DIR}/modules" "${modpath[@]}") + allModules=("${(f)$(find "${modpath[@]}" -type f -perm +u=x -maxdepth 1 2> /dev/null | sort -n)}") filterModules [ "${list}" = true ] && printModulesToInstall } function main() { eval "`docopts -f -V - -h - : "$@" <<- USAGE - Usage: $0 [options] [...] + Usage: $0 [options] [-m PATH]... [...] - Install all included modules. If any arg is given, install only those - modules. + Install all modules in module search path. If any arg is given, + install only modules that either match any given or whose path ends + like any of the given . Options: - -i, --inverse Exclude the given instead. - -l, --list List modules that are going to be installed and exit without - installation. + -i, --inverse Exclude the given instead. + -m PATH, --modpath PATH Include PATH in the module search path. + -l, --list List modules that are going to be installed and + exit without installation. Modules are printed in + minimal but still distinct paths. ---- $0 0.1.0 Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG diff --git a/spec/filterModules_spec.sh b/spec/filterModules_spec.sh index e22332e..1de8cb9 100644 --- a/spec/filterModules_spec.sh +++ b/spec/filterModules_spec.sh @@ -15,6 +15,14 @@ Describe 'filterModules' The status should be success End + It 'matches modules by ending pattern' + allModules=(dir1/module1 dir2/module1 /dir/module1/'module3 with space') modulesToInstall=() + module=(module1) + When call filterModules + The variable modulesToInstall should eq 'dir1/module1 dir2/module1' + The status should be success + End + It 'returns only not mentioned modules if inversed' allModules=(module1 module2 'module3 with space') modulesToInstall=() module=('module3 with space' module1)