jw-pkg: Add command get-value-from-tables

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2024-06-25 11:19:23 +00:00
commit 5e66868557

View file

@ -328,6 +328,37 @@ cmd_compile_templates()
fi
}
cmd_get_value_from_tables()
{
local key show_file
eval set -- `getopt -- k: "$@"`
while [ "$1" != -- ]; do
case $1 in
-k)
key=$2
shift
;;
-f)
show_file=1
shift
;;
*)
echo -e "Unexpected argument >$1<\n" >&2
usage 1
;;
esac
shift
done
shift
local f
while read f; do
grep -q "^\s*$key\s\+" $f || continue
[ "$show_file" = 1 ] && echo -n "$f: "
sed "s|^[ ]*#.*||; /^\s*$key\(\s\|=\)\+/ !d; s/^\s*$key\(\s\|=\)\+//" $f
done <<< $(cmd_list_template_tables "$@")
}
cmd_built_today()
{
local today=`date +'%Y-%m-%d'`
@ -410,7 +441,7 @@ list)
list_projects)
list_projects "$@"
;;
compile_templates|list_templates|list_template_tables|list_template_output|rm_template_output|diff|build_date|built_today|rpmnew)
compile_templates|list_templates|list_template_tables|list_template_output|rm_template_output|diff|build_date|built_today|rpmnew|get_value_from_tables)
cmd_$cmd "$@"
;;
help)