modify: clean up duplicated code

Signed-off-by: Leah Rowe <leah@libreboot.org>
fsdg20230625
Leah Rowe 2023-05-18 11:24:08 +01:00
parent f7f3aef17e
commit 9fb489ac3e
1 changed files with 7 additions and 14 deletions

21
modify
View File

@ -51,10 +51,10 @@ main()
case "${option}" in case "${option}" in
list) list)
printf "Options for mode '%s':\n\n" ${mode} printf "Options for mode '%s':\n\n" ${mode}
listoptions "${mode}" listitems "${modify}/${mode}"
;; ;;
all) all)
for option in $(listoptions "${mode}"); do for option in $(listitems "${modify}/${mode}"); do
"${modify}/${mode}/${option}" $@ "${modify}/${mode}/${option}" $@
done done
;; ;;
@ -71,21 +71,13 @@ main()
esac esac
} }
# Takes exactly one mode as parameter
listoptions()
{
for option in "${modify}/${1}/"*; do
printf '%s\n' ${option##*/}
done
}
help() help()
{ {
cat <<- EOF cat <<- EOF
USAGE: ./modify <MODE> <OPTION> USAGE: ./modify <MODE> <OPTION>
possible values for 'mode': possible values for 'mode':
$(listmodes) $(listitems "${modify}")
Example: ./modify coreboot configs Example: ./modify coreboot configs
Example: ./modify coreboot configs x60 Example: ./modify coreboot configs x60
@ -94,10 +86,11 @@ help()
EOF EOF
} }
listmodes() listitems()
{ {
for mode in "${modify}/"*; do for x in "${1}/"*; do
printf '%s\n' "${mode##*/}" [ ! -f "${x}" ] && continue
printf "%s\n" ${x##*/}
done done
} }