From 5e6686855700942d9b3b33cec1b4deaf0b1b644e Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Tue, 25 Jun 2024 11:19:23 +0000 Subject: [PATCH] jw-pkg: Add command get-value-from-tables Signed-off-by: Jan Lindemann --- scripts/jw-pkg | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/jw-pkg b/scripts/jw-pkg index ea89441c..20e1fd87 100644 --- a/scripts/jw-pkg +++ b/scripts/jw-pkg @@ -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)