From 1e4a96730da70fcfa3b8c153874cbdebad0f9829 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 27 Jan 2013 19:41:28 +0100 Subject: o Starting on a style guide. app-conf: Adding 'import' command. app-cat-conf: Adding support for multiple -f flags. The default files can be switched off. A file named "-" is the same as /dev/stdin. app: Adding a way to enable debugging. app-install-file: Import any configuration delivered with the package. --- libexec/app-cat-conf | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) (limited to 'libexec/app-cat-conf') diff --git a/libexec/app-cat-conf b/libexec/app-cat-conf index 5b1c614..857ecaf 100755 --- a/libexec/app-cat-conf +++ b/libexec/app-cat-conf @@ -10,14 +10,23 @@ APPSH_HOME=$(cd $(dirname "$0")/.. && pwd) key_expr="[a-zA-Z][_a-zA-Z0-9]*" -file=.app/config +files=() name="" +use_default_files=yes -while getopts "f:n:" opt +while getopts "f:Dn:" opt do case $opt in f) file=$OPTARG + if [[ $file == "-" ]] + then + file=/dev/stdin + fi + files+=($file) + ;; + D) + use_default_files=no ;; n) name=$OPTARG @@ -29,6 +38,19 @@ do esac done +if [[ $use_default_files == yes ]] +then + if [ -r ".app/config" ] + then + files+=(".app/config") + fi + + files+=(${APPSH_DEFAULT_CONFIG-$APPSH_HOME/lib/default-config}) +fi + +# TODO: find config files in the paths above $file's paths and perhaps +# /etc/appsh/config. + if [ -z "$name" ] then filter="s,^[ ]*\($key_expr\.$key_expr\)[ ]*=[ ]*\(.*\)$,\1=\2,p" @@ -36,17 +58,10 @@ else filter="s,^\($name\)=\(.*\),\1=\2,p" fi -APPSH_DEFAULT_CONFIG=${APPSH_DEFAULT_CONFIG-$APPSH_HOME/lib/default-config} - -# TODO: find config files in the paths above $file's paths and perhaps /etc/appsh/config - -if [[ ! -r $file ]] -then - fatal "No such file: $file" -fi +debug "Using files:" "${files[@]}" -# The awk script makes sure each key only appears once -cat "$file" "$APPSH_DEFAULT_CONFIG" | \ +# The awk script makes sure each key only appears once. The first one wins +cat "${files[@]}" | \ sed -n -e "$filter" | \ awk -F = ' (!($1 in a)){a[$1]; print }' | \ sort -- cgit v1.2.3