aboutsummaryrefslogtreecommitdiff
path: root/libexec/app-cat-conf
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2013-01-27 19:41:28 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2013-01-27 19:49:58 +0100
commit1e4a96730da70fcfa3b8c153874cbdebad0f9829 (patch)
tree9495f33f6b54621e0a684b553b64a6958744c1e3 /libexec/app-cat-conf
parente1daac32c5b7ca0d902c16135d361aa5303f5124 (diff)
downloadapp.sh-1e4a96730da70fcfa3b8c153874cbdebad0f9829.tar.gz
app.sh-1e4a96730da70fcfa3b8c153874cbdebad0f9829.tar.bz2
app.sh-1e4a96730da70fcfa3b8c153874cbdebad0f9829.tar.xz
app.sh-1e4a96730da70fcfa3b8c153874cbdebad0f9829.zip
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.
Diffstat (limited to 'libexec/app-cat-conf')
-rwxr-xr-xlibexec/app-cat-conf39
1 files changed, 27 insertions, 12 deletions
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