diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2013-10-26 17:44:19 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2013-10-26 17:48:45 +0200 |
commit | 165d20eebc587f21f0409850b8e522c7a25979e3 (patch) | |
tree | fb127d7270b5a2f5152ab1dddeac306e38850c93 /libexec/app-cat-conf | |
parent | 2474a9e50e5d21ed6b3fd825d9fe565b79f62014 (diff) | |
download | app.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-x | libexec/app-cat-conf | 54 |
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 }' | \ |