aboutsummaryrefslogtreecommitdiff
path: root/libexec/app-cat-conf
diff options
context:
space:
mode:
Diffstat (limited to 'libexec/app-cat-conf')
-rwxr-xr-xlibexec/app-cat-conf54
1 files changed, 39 insertions, 15 deletions
diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf
index 49d3284..6e2567f 100755
--- a/libexec/app-cat-conf
+++ b/libexec/app-cat-conf
@@ -13,12 +13,12 @@ key_expr="[a-zA-Z][_a-zA-Z0-9]*"
files=()
arg_files=()
declare -a arg_files
-name=""
use_default_files=yes
location=app
+mode=all
-while getopts "f:Dn:l:" opt
+while getopts "f:Dk:g:l:" opt
do
case $opt in
f)
@@ -32,18 +32,40 @@ do
D)
use_default_files=no
;;
- n)
- name=$OPTARG
+ k)
+ key=$OPTARG
+ mode=key
+ if [[ ! $key =~ $key_expr\.$key_expr ]]
+ then
+ echo Invalid key name: $key
+ exit 1
+ fi
+ ;;
+ g)
+ group=$OPTARG
+ mode=group
+ if [[ ! $group =~ $key_expr ]]
+ then
+ echo Invalid group name: $group
+ exit 1
+ fi
;;
l)
location=$OPTARG
;;
- \?)
+ *)
usage "Invalid option: $opt"
;;
esac
done
+shift $(($OPTIND - 1))
+
+if [[ $# != 0 ]]
+then
+ usage "extra arguments"
+fi
+
validate_location location
if [[ $use_default_files == yes ]]
@@ -72,20 +94,22 @@ then
files+=("${arg_files[@]}")
fi
-# TODO: find config files in the paths above $file's paths and perhaps
-# /etc/appsh/config.
+case $mode in
+ all)
+ filter="$key_expr\.$key_expr"
+ ;;
+ group)
+ filter="$group\.$key_expr"
+ ;;
+ key)
+ filter=$key
+ ;;
+esac
-if [ -z "$name" ]
-then
- filter="s,^[ ]*\($key_expr\.$key_expr\)[ ]*=[ ]*\(.*\)$,\1=\2,p"
-else
- filter="s,^\($name\)=\(.*\),\1=\2,p"
-fi
+filter="s,^[ ]*\($filter\)[ ]*=[ ]*\(.*\)$,\1=\2,p"
debug "Using files:" "${files[@]}"
-# The awk script makes sure each key only appears once. The first one wins
-
(for ((idx=${#files[@]}-1 ; idx>=0 ; idx-- )); do cat ${files[idx]}; done) | \
sed -n -e "$filter" | \
awk -F = ' (!($1 in a)){a[$1]; print }' | \