diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-17 16:04:13 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2012-10-17 21:05:49 +0200 |
commit | 2670ff51db825005901099e490fa2332de6fb6fe (patch) | |
tree | 5d9942f011545f2c314781b5a2dd9fd914feedcb /.app/lib | |
parent | 3d9342dfdad8fb8e350227666a1dc2c658be8e08 (diff) | |
download | app.sh-2670ff51db825005901099e490fa2332de6fb6fe.tar.gz app.sh-2670ff51db825005901099e490fa2332de6fb6fe.tar.bz2 app.sh-2670ff51db825005901099e490fa2332de6fb6fe.tar.xz app.sh-2670ff51db825005901099e490fa2332de6fb6fe.zip |
o Adding a list-group method to list.
Diffstat (limited to '.app/lib')
-rw-r--r-- | .app/lib/app-conf | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/.app/lib/app-conf b/.app/lib/app-conf index 39b2e0d..c9204e9 100644 --- a/.app/lib/app-conf +++ b/.app/lib/app-conf @@ -1,7 +1,19 @@ #!/bin/bash +# TODO: Add a 'get' method that returns a single value +# Exit with 0 if found, 1 otherwise. + key_expr="[a-zA-Z][_a-zA-Z0-9]*\.[a-zA-Z][_a-zA-Z0-9]*" +format_conf() { + local IFS== + while read key value + do + printf "%-20s %-20s" "$key" "$value" + echo + done +} + get_conf() { local BASEDIR=$1 local name=$2 @@ -54,8 +66,7 @@ get_conf_in_group() { local instance=$3 local group=$4 - get_conf_all "$BASEDIR" "$name" "$instance" | \ - sed -n "s,^[ ]*${group}\.\([._a-zA-Z]*\)=\(.*\)$,\1=\2,p" + get_conf_all "$BASEDIR" "$name" "$instance" | sed -n "s,^${group}\.\(.*\),\1,p" } assert_key() { @@ -107,11 +118,7 @@ method_conf_list() { local name=$1; shift local instance=$1; shift - get_conf_all "$BASEDIR" "$name" "$instance" | (IFS==; while read key value - do - printf "%-20s %-20s" "$key" "$value" - echo - done) + get_conf_all "$BASEDIR" "$name" "$instance" | format_conf } method_conf_usage() { @@ -123,7 +130,8 @@ method_conf_usage() { echo "usage: $0 conf <method>" >&2 echo "" echo "Available methods:" >&2 - echo " get - list all configuration parameters" >&2 + echo " list - list all configuration values" >&2 + echo " list-group [group] - list all configuration values in the specified group" >&2 echo " set [group.key] [value] - set a configuration parameter" >&2 echo " delete [group.key] - deletes a configuration parameter" >&2 exit 1 @@ -151,6 +159,15 @@ method_conf() { method_conf_list "$name" "$instance" ;; + list-group) + if [ $# -ne 1 ] + then + method_conf_usage + exit 1 + fi + + get_conf_in_group "$BASEDIR" "$name" "$instance" "$1" | format_conf + ;; set) if [ $# -ne 2 ] then |