aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/app-conf2
-rw-r--r--docs/Makefile6
-rw-r--r--docs/app-cat-conf.txt53
-rw-r--r--docs/app-conf.txt1
-rw-r--r--docs/app.txt16
-rwxr-xr-xlib/common2
-rwxr-xr-xlibexec/app-cat-conf54
-rwxr-xr-xtest/app-cat-conf.bats71
8 files changed, 145 insertions, 60 deletions
diff --git a/bin/app-conf b/bin/app-conf
index 96e52cf..23b68f7 100755
--- a/bin/app-conf
+++ b/bin/app-conf
@@ -140,7 +140,7 @@ case "$command" in
usage
fi
- app-cat-conf -l "$location" -n "$1" | cut -f 2- -d =
+ app-cat-conf -l "$location" -k "$1" | cut -f 2- -d =
;;
list)
if [ $# -gt 0 ]
diff --git a/docs/Makefile b/docs/Makefile
index c62e70c..8b8cf8b 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -4,10 +4,12 @@ MAN=$(patsubst %.txt,%.1,$(TXT))
all: $(HTML) $(MAN)
%.html: %.txt
- asciidoc -a data-uri -a icons -a toc -a max-width=55em $<
+ @echo asciidoc $<
+ @asciidoc -a data-uri -a icons -a toc -a max-width=55em $<
%.1: %.txt
- a2x --doctype manpage --format manpage $<
+ @echo a2x $<
+ @a2x --doctype manpage --format manpage $<
clean:
rm -rf $(wildcard *.html) $(wildcard *.1)
diff --git a/docs/app-cat-conf.txt b/docs/app-cat-conf.txt
new file mode 100644
index 0000000..0411390
--- /dev/null
+++ b/docs/app-cat-conf.txt
@@ -0,0 +1,53 @@
+app-cat-conf(1)
+===============
+
+NAME
+----
+app-cat-conf - outputs a combined configuration file in a parseable
+format
+
+SYNOPSIS
+--------
+[verse]
+'app-cat-conf' [-f <file>] [-D] [-l <location>] [-k <key>]
+
+DESCRIPTION
+-----------
+Outputs the combined file from all the input files. It will only
+output a key once, the last value for each key seen will win.
+
+A configuration file is a collection of grouped keys and values,
+similar to Git.
+
+The keys consits of two parts: a _group_ and a _name_. Both have to
+match the regex `[a-zA-Z0-9]` and are combined with a dot.
+
+OPTIONS
+-------
+-f::
+ The config file to use. If the value is '-', stdin will be used as
+ input. The option can be given multiple times.
+-D::
+ Disables the inclusion of the default files.
+-k::
+ Looks up the given key.
+-l::
+ Selects the location to use.
+
+LOCATIONS AND DEFAULT FILES
+---------------------------
+
+'app-cat-conf' will by default look for configuration files in three places:
+
+. $APPSH_HOME/lib/default-config
+
+. $HOME/.appconfig
+
+. .app/config
+
+SEE ALSO
+--------
+
+git-config(1)
+
+// vim: set ft=asciidoc:
diff --git a/docs/app-conf.txt b/docs/app-conf.txt
index 27d995a..c686960 100644
--- a/docs/app-conf.txt
+++ b/docs/app-conf.txt
@@ -5,7 +5,6 @@ NAME
----
app-conf - configuration management
-
SYNOPSIS
--------
[verse]
diff --git a/docs/app.txt b/docs/app.txt
index 4756ef2..49ed59e 100644
--- a/docs/app.txt
+++ b/docs/app.txt
@@ -11,6 +11,16 @@ SYNOPSIS
[verse]
'app' <options>
+QUICK START
+~~~~~~~~~~~
+
+ $ app init -d my-app maven org.example:my-app:1.0-SNAPSHOT
+ $ cd my-app
+ $ app start
+ $ app conf set app.version 1.0
+ $ app upgrade
+ $ app restart
+
INSTALLING AN APPLICATION
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -80,4 +90,10 @@ TODOs
* Find a way to check if an application is running.
+SEE ALSO
+--------
+
+* app-conf
+* app-cat-conf
+
// vim: set ft=asciidoc:
diff --git a/lib/common b/lib/common
index be3daae..663bf45 100755
--- a/lib/common
+++ b/lib/common
@@ -247,7 +247,7 @@ run_app() {
done
local bin=$1; shift
- local e=`app-cat-conf -n "env\..*" | cut -f 2- -d .`
+ local e=`app-cat-conf -g env | cut -f 2- -d .`
local app_home=`pwd`
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 }' | \
diff --git a/test/app-cat-conf.bats b/test/app-cat-conf.bats
index 2acdd99..c1fd09b 100755
--- a/test/app-cat-conf.bats
+++ b/test/app-cat-conf.bats
@@ -5,11 +5,11 @@ load utils
setup_inner() {
export APPSH_DEFAULT_CONFIG=/dev/null
+ cd $APPSH_HOME/test/data/app-cat-conf
}
@test "app-cat-conf" {
- app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1
- echo_lines
+ app_libexec app-cat-conf -f config-1
eq '${lines[0]}' "baz.kiz=zap"
eq '${lines[1]}' "baz.wat=baz"
eq '${lines[2]}' "foo.bar=wat"
@@ -18,77 +18,62 @@ setup_inner() {
eq '${#lines[*]}' 5
}
+@test "app-cat-conf -k baz.wat" {
+ app_libexec app-cat-conf -f config-1 -k baz.wat
+ eq '${lines[0]}' "baz.wat=baz"
+ eq '${#lines[*]}' 1
+}
+
@test "app-cat-conf -g baz" {
- app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1 -n "baz\..*"
- echo_lines
+ app_libexec app-cat-conf -f config-1 -g baz
eq '${lines[0]}' "baz.kiz=zap"
eq '${lines[1]}' "baz.wat=baz"
eq '${#lines[*]}' 2
}
-@test "app-cat-conf -k wat" {
- app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1 -n ".*\.wat"
- echo_lines
- eq '${lines[0]}' "baz.wat=baz"
- eq '${lines[1]}' "foo.wat=foo"
- eq '${#lines[*]}' 2
-}
-
-@test "app-cat-conf -g baz -k wat" {
- app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-1 -n "baz\.wat"
- echo_lines
- eq '${lines[0]}' "baz.wat=baz"
- eq '${#lines[*]}' 1
-}
-
@test "app-cat-conf can use stdin and multiple files" {
- x=$(cat $APPSH_HOME/test/data/app-cat-conf/config-3 | \
- $APPSH_HOME/libexec/app-cat-conf -D -f - -f $APPSH_HOME/test/data/app-cat-conf/config-2)
+ x=$(cat config-3 | \
+ $APPSH_HOME/libexec/app-cat-conf -D -f - -f config-2)
[[ $x == "foo.bar=wat
foo.wat=bar" ]]
}
@test "app-cat-conf read multiple files, last file wins" {
app_libexec app-cat-conf \
- -f $APPSH_HOME/test/data/app-cat-conf/config-2 \
- -f $APPSH_HOME/test/data/app-cat-conf/config-4
- echo_lines
+ -f config-2 \
+ -f config-4
eq '${lines[0]}' "foo.bar=foo"
eq '${#lines[*]}' 1
}
@test "uses \$APPSH_DEFAULT_CONFIG" {
- APPSH_DEFAULT_CONFIG=$APPSH_HOME/test/data/app-cat-conf/config-2
+ APPSH_DEFAULT_CONFIG=`pwd`/config-2
app_libexec app-cat-conf -f /dev/null
- echo_lines
eq '${lines[0]}' "foo.bar=wat"
eq '${#lines[*]}' 1
}
@test "uses \$APPSH_DEFAULT_CONFIG, with lowest priority" {
- app_libexec app-cat-conf -f $APPSH_HOME/test/data/app-cat-conf/config-3
- echo_lines
+ app_libexec app-cat-conf -f config-3
eq '${lines[0]}' "foo.bar=baz"
eq '${lines[1]}' "foo.wat=bar"
eq '${#lines[*]}' 2
}
@test "app-cat-conf - read installation's and user's config when outside app" {
- HOME=$APPSH_HOME/test/data/app-cat-conf/home
- APPSH_DEFAULT_CONFIG=$APPSH_HOME/test/data/app-cat-conf/config-2
- app_libexec app-cat-conf; echo_lines
- eq '$status' 0
+ HOME=`pwd`/home
+ APPSH_DEFAULT_CONFIG=config-2
+ app_libexec app-cat-conf
eq '${lines[0]}' "foo.bar=1"
eq '${lines[1]}' "foo.foo=2"
eq '${#lines[*]}' 2
}
@test "app-cat-conf - read \$HOME/.appconfig and .app/config when inside app" {
- HOME=$APPSH_HOME/test/data/app-cat-conf/home
- APPSH_DEFAULT_CONFIG=$APPSH_HOME/test/data/app-cat-conf/config-2
- cd $APPSH_HOME/test/data/app-cat-conf/my-app
- app_libexec app-cat-conf; echo_lines
- eq '$status' 0
+ HOME=`pwd`/home
+ APPSH_DEFAULT_CONFIG=`pwd`/config-2
+ cd my-app
+ app_libexec app-cat-conf
eq '${lines[0]}' "foo.bar=2"
eq '${lines[1]}' "foo.baz=3"
eq '${lines[2]}' "foo.foo=2"
@@ -97,10 +82,16 @@ foo.wat=bar" ]]
@test "app-cat-conf -l u - read only \$HOME/.appconfig even when in an app" {
HOME=$APPSH_HOME/test/data/app-cat-conf/home
- cd $APPSH_HOME/test/data/app-cat-conf/my-app
- app_libexec app-cat-conf -l u; echo_lines
- eq '$status' 0
+ cd my-app
+ app_libexec app-cat-conf -l u
eq '${lines[0]}' "foo.bar=1"
eq '${lines[1]}' "foo.foo=2"
eq '${#lines[*]}' 2
}
+
+@test "app-cat-conf; extra arguments" {
+ check_status=no
+ app_libexec app-cat-conf zoot
+ eq '$status' 1
+ eq '${#lines[*]}' 1
+}