Use outer array in filterModules
This commit is contained in:
16
install.sh
16
install.sh
@@ -15,20 +15,20 @@ function autoloadZShLib() {
|
|||||||
autoload -Uz "${funcNames[@]}"
|
autoload -Uz "${funcNames[@]}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFilteredModules() {
|
function filterModules() {
|
||||||
if [ "${#module}" -eq 0 ]; then
|
if [ "${#module}" -eq 0 ]; then
|
||||||
echo "${allModules[@]}"
|
modulesToInstall=("${allModules[@]}")
|
||||||
else
|
else
|
||||||
local mod modulesToKeep=()
|
local mod
|
||||||
|
modulesToInstall=()
|
||||||
for mod in "${allModules[@]}"; do
|
for mod in "${allModules[@]}"; do
|
||||||
local foundAtIndex="${module[(Ie)${mod}]}"
|
local foundAtIndex="${module[(Ie)${mod}]}"
|
||||||
if [ "${inverse}" != 'true' -a "${foundAtIndex}" -gt 0 ]; then
|
if [ "${inverse}" != 'true' -a "${foundAtIndex}" -gt 0 ]; then
|
||||||
modulesToKeep+=("${mod}")
|
modulesToInstall+=("${mod}")
|
||||||
elif [ "${inverse}" = 'true' -a "${foundAtIndex}" -eq 0 ]; then
|
elif [ "${inverse}" = 'true' -a "${foundAtIndex}" -eq 0 ]; then
|
||||||
modulesToKeep+=("${mod}")
|
modulesToInstall+=("${mod}")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
echo "${modulesToKeep[@]}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,8 +170,8 @@ function main() {
|
|||||||
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
||||||
License EUPL-1.2. There is NO WARRANTY, to the extent permitted by law.
|
License EUPL-1.2. There is NO WARRANTY, to the extent permitted by law.
|
||||||
USAGE`"
|
USAGE`"
|
||||||
local allModules=("${(f)$(find ./modules -type f -perm +u=x -maxdepth 1 2> /dev/null | awk -F/ '{print $NF }' | sort -n)}")
|
local allModules=("${(f)$(find ./modules -type f -perm +u=x -maxdepth 1 2> /dev/null | awk -F/ '{print $NF }' | sort -n)}") modulesToInstall
|
||||||
local modulesToInstall=(`getFilteredModules`)
|
filterModules
|
||||||
ensureDocopts
|
ensureDocopts
|
||||||
autoloadZShLib
|
autoloadZShLib
|
||||||
askNecessaryQuestions
|
askNecessaryQuestions
|
||||||
|
|||||||
26
spec/filterModules_spec.sh
Normal file
26
spec/filterModules_spec.sh
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
Describe 'filterModules'
|
||||||
|
Include ./install.sh
|
||||||
|
It 'returns all modules if no module arg is given'
|
||||||
|
allModules=(module1 module2 'module3 with space') modulesToInstall=()
|
||||||
|
When call filterModules
|
||||||
|
The variable modulesToInstall should eq 'module1 module2 module3 with space'
|
||||||
|
The status should be success
|
||||||
|
End
|
||||||
|
|
||||||
|
It 'returns only mentioned modules'
|
||||||
|
allModules=(module1 module2 'module3 with space') modulesToInstall=()
|
||||||
|
module=('module3 with space' module2)
|
||||||
|
When call filterModules
|
||||||
|
The variable modulesToInstall should eq 'module2 module3 with space'
|
||||||
|
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)
|
||||||
|
inverse=true
|
||||||
|
When call filterModules
|
||||||
|
The variable modulesToInstall should eq 'module2'
|
||||||
|
The status should be success
|
||||||
|
End
|
||||||
|
End
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
Describe 'getFilteredModules'
|
|
||||||
Include ./install.sh
|
|
||||||
It 'returns all modules if no module arg is given'
|
|
||||||
allModules=(module1 module2)
|
|
||||||
When call getFilteredModules
|
|
||||||
The output should eq 'module1 module2'
|
|
||||||
The status should be success
|
|
||||||
End
|
|
||||||
|
|
||||||
It 'returns only mentioned modules'
|
|
||||||
allModules=(module1 module2 module3)
|
|
||||||
module=(module3 module2)
|
|
||||||
When call getFilteredModules
|
|
||||||
The output should eq 'module2 module3'
|
|
||||||
The status should be success
|
|
||||||
End
|
|
||||||
|
|
||||||
It 'returns only not mentioned modules if inversed'
|
|
||||||
allModules=(module1 module2 module3)
|
|
||||||
module=(module3 module1)
|
|
||||||
inverse=true
|
|
||||||
When call getFilteredModules
|
|
||||||
The output should eq 'module2'
|
|
||||||
The status should be success
|
|
||||||
End
|
|
||||||
End
|
|
||||||
Reference in New Issue
Block a user