aboutsummaryrefslogtreecommitdiff
path: root/libexec/app-cat-conf
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-10-26 17:44:19 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2013-10-26 17:48:45 +0200
commit165d20eebc587f21f0409850b8e522c7a25979e3 (patch)
treefb127d7270b5a2f5152ab1dddeac306e38850c93 /libexec/app-cat-conf
parent2474a9e50e5d21ed6b3fd825d9fe565b79f62014 (diff)
downloadapp.sh-165d20eebc587f21f0409850b8e522c7a25979e3.tar.gz
app.sh-165d20eebc587f21f0409850b8e522c7a25979e3.tar.bz2
app.sh-165d20eebc587f21f0409850b8e522c7a25979e3.tar.xz
app.sh-165d20eebc587f21f0409850b8e522c7a25979e3.zip
app-cat-conf: Removing -n argument, adding -k and -g for 'key' and
'group' lookups.
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 }' | \