Add suffix module filtering and module search path
This commit is contained in:
31
install.sh
31
install.sh
@@ -19,13 +19,14 @@ function filterModules() {
|
|||||||
if [ "${#module}" -eq 0 ]; then
|
if [ "${#module}" -eq 0 ]; then
|
||||||
modulesToInstall=("${allModules[@]}")
|
modulesToInstall=("${allModules[@]}")
|
||||||
else
|
else
|
||||||
local mod
|
local mod pattern="^.*(${(j.|.)module})\$"
|
||||||
modulesToInstall=()
|
modulesToInstall=()
|
||||||
for mod in "${allModules[@]}"; do
|
for mod in "${allModules[@]}"; do
|
||||||
local foundAtIndex="${module[(Ie)${mod}]}"
|
local found=false
|
||||||
if [ "${inverse}" != 'true' -a "${foundAtIndex}" -gt 0 ]; then
|
[[ "${mod}" =~ ${pattern} ]] && found=true
|
||||||
|
if [ "${inverse}" != 'true' -a "${found}" = true ]; then
|
||||||
modulesToInstall+=("${mod}")
|
modulesToInstall+=("${mod}")
|
||||||
elif [ "${inverse}" = 'true' -a "${foundAtIndex}" -eq 0 ]; then
|
elif [ "${inverse}" = 'true' -a "${found}" = false ]; then
|
||||||
modulesToInstall+=("${mod}")
|
modulesToInstall+=("${mod}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@@ -159,28 +160,32 @@ function askNecessaryQuestions() {
|
|||||||
function printModulesToInstall() {
|
function printModulesToInstall() {
|
||||||
hio info 'Modules that will install are:'
|
hio info 'Modules that will install are:'
|
||||||
for mod in "${modulesToInstall[@]}"; do
|
for mod in "${modulesToInstall[@]}"; do
|
||||||
hio debug "${mod}"
|
echo "${mod}"
|
||||||
done
|
done | abbreviatePaths
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadModules() {
|
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
|
filterModules
|
||||||
[ "${list}" = true ] && printModulesToInstall
|
[ "${list}" = true ] && printModulesToInstall
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
eval "`docopts -f -V - -h - : "$@" <<- USAGE
|
eval "`docopts -f -V - -h - : "$@" <<- USAGE
|
||||||
Usage: $0 [options] [<module>...]
|
Usage: $0 [options] [-m PATH]... [<module>...]
|
||||||
|
|
||||||
Install all included modules. If any <module> arg is given, install only those
|
Install all modules in module search path. If any <module> arg is given,
|
||||||
modules.
|
install only modules that either match any given <module> or whose path ends
|
||||||
|
like any of the given <module>.
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
-i, --inverse Exclude the given <module> instead.
|
-i, --inverse Exclude the given <module> instead.
|
||||||
-l, --list List modules that are going to be installed and exit without
|
-m PATH, --modpath PATH Include PATH in the module search path.
|
||||||
installation.
|
-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
|
$0 0.1.0
|
||||||
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ Describe 'filterModules'
|
|||||||
The status should be success
|
The status should be success
|
||||||
End
|
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'
|
It 'returns only not mentioned modules if inversed'
|
||||||
allModules=(module1 module2 'module3 with space') modulesToInstall=()
|
allModules=(module1 module2 'module3 with space') modulesToInstall=()
|
||||||
module=('module3 with space' module1)
|
module=('module3 with space' module1)
|
||||||
|
|||||||
Reference in New Issue
Block a user