Add module filtering to install.sh/main
This commit is contained in:
2
.shellspec
Normal file
2
.shellspec
Normal file
@@ -0,0 +1,2 @@
|
||||
--require autoload
|
||||
--shell /bin/zsh
|
||||
36
install.sh
36
install.sh
@@ -15,10 +15,44 @@ function autoloadZShLib() {
|
||||
autoload -Uz "${funcNames[@]}"
|
||||
}
|
||||
|
||||
function getFilteredModules() {
|
||||
if [ "${#module}" -eq 0 ]; then
|
||||
echo "${allModules[@]}"
|
||||
else
|
||||
local modulesToKeep=()
|
||||
for mod in "${allModules[@]}"; do
|
||||
local foundAtIndex="${module[(Ie)${mod}]}"
|
||||
if [ "${inverse}" != 'true' -a "${foundAtIndex}" -gt 0 ]; then
|
||||
modulesToKeep+=("${mod}")
|
||||
elif [ "${inverse}" = 'true' -a "${foundAtIndex}" -eq 0 ]; then
|
||||
modulesToKeep+=("${mod}")
|
||||
fi
|
||||
done
|
||||
echo "${modulesToKeep[@]}"
|
||||
fi
|
||||
}
|
||||
|
||||
function main() {
|
||||
eval "`docopts -f -V - -h - : "$@" <<- USAGE
|
||||
Usage: $0 [options] [<module>...]
|
||||
|
||||
Install all included modules. If any <module> arg is given, install only those
|
||||
modules.
|
||||
|
||||
Options:
|
||||
-i, --inverse Exclude the given <module> instead.
|
||||
----
|
||||
$0 0.1.0
|
||||
Copyright (C) 2022 Rezart Qelibari, Astzweig GmbH & Co. KG
|
||||
License EUPL-1.2. There is NO WARRANTY, to the extent permitted by law.
|
||||
USAGE`"
|
||||
local allModules=()
|
||||
local modulesToInstall=(`getFilteredModules`)
|
||||
ensureDocopts
|
||||
autoloadZShLib
|
||||
hio debug "Current working dir is: `pwd`"
|
||||
}
|
||||
|
||||
main
|
||||
if [[ "${ZSH_EVAL_CONTEXT}" == toplevel ]]; then
|
||||
main
|
||||
fi
|
||||
|
||||
4
spec/autoload.sh
Normal file
4
spec/autoload.sh
Normal file
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env zsh
|
||||
FPATH="`pwd`/zshlib:${FPATH}"
|
||||
local funcNames=("${(@f)$(find . -type f -perm +u=x -maxdepth 1 | awk -F/ '{ print $NF }')}")
|
||||
autoload -Uz "${funcNames[@]}"
|
||||
26
spec/getFilteredModules_spec.sh
Normal file
26
spec/getFilteredModules_spec.sh
Normal file
@@ -0,0 +1,26 @@
|
||||
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