aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rwxr-xr-xbin/app-conf8
-rwxr-xr-xbin/app-init3
-rwxr-xr-xlib/common10
-rwxr-xr-xtest/app-conf.bats43
-rw-r--r--test/utils.bash6
6 files changed, 46 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index 05ffacb..c61e002 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ show-tests:
@echo TESTS=$(TESTS)
@echo $(addprefix set_header-,$(BINS))
-test: show-tests $(TESTS)
+test: $(TESTS)
.PHONY: test
docs:
diff --git a/bin/app-conf b/bin/app-conf
index 88498e9..cd127a2 100755
--- a/bin/app-conf
+++ b/bin/app-conf
@@ -28,7 +28,7 @@ format_conf() {
local IFS==
while read key value
do
- printf "%-20s %-20s" "$key" "$value"
+ printf "%-20s %s" "$key" "$value"
echo
done
}
@@ -140,12 +140,12 @@ case "$command" in
usage
fi
- app-cat-conf -l "$location" -n "$1" | cut -f 2 -d = | format_conf | sed "s, *$,,"
+ app-cat-conf -l "$location" -n "$1" | cut -f 2- -d =
;;
list)
if [ $# -gt 0 ]
then
- usage "Extra options."
+ usage "Extra arguments."
fi
app-cat-conf -l "$location" | format_conf
@@ -153,7 +153,7 @@ case "$command" in
set)
if [ $# -ne 2 ]
then
- usage
+ usage "Expected exactly two arguments"
fi
conf_set "$file" "$1" "$2"
diff --git a/bin/app-init b/bin/app-init
index 7098cb3..fb4f7cd 100755
--- a/bin/app-init
+++ b/bin/app-init
@@ -12,6 +12,7 @@ usage_text() {
echo "usage: $usage_app -d dir <resolver> <resolver args>"
}
+dir=
while getopts "d:" opt
do
case $opt in
@@ -32,7 +33,7 @@ resolver_name="$1"; shift
if [ -z "$dir" ]
then
- usage
+ usage "-d is required"
fi
if [ -e "$dir" ]
diff --git a/lib/common b/lib/common
index 9e0db84..be3daae 100755
--- a/lib/common
+++ b/lib/common
@@ -199,7 +199,12 @@ _get_config_file_system() {
}
_get_config_file_user() {
- eval $1="$HOME/.appconfig"
+ if [[ -z $HOME ]]
+ then
+ eval $1=""
+ else
+ eval $1="$HOME/.appconfig"
+ fi
}
_get_config_file_app() {
@@ -289,6 +294,9 @@ find_resolver() {
# overload their implementations.
PATH=$PATH:$APPSH_HOME/bin:$APPSH_HOME/libexec
+# Make sure that $HOME is present to prevent unbound errors
+HOME=${HOME:-}
+
# Save for later
usage_app=${0##*/}
echo_debug=${echo_debug-no}
diff --git a/test/app-conf.bats b/test/app-conf.bats
index d1a2b18..5c5da05 100755
--- a/test/app-conf.bats
+++ b/test/app-conf.bats
@@ -18,12 +18,12 @@ setup_inner() {
app conf set g.FOO bar
app conf
- eq '${lines[0]}' "app.bin bin/app-a "
- eq '${lines[1]}' "g.FOO bar "
+ eq '${lines[0]}' "app.bin bin/app-a"
+ eq '${lines[1]}' "g.FOO bar"
eq '${#lines[*]}' 2
app conf get g.FOO
- eq '${lines[0]}' "bar"
+ eq '${lines[0]}' "bar"
eq '${#lines[*]}' 1
app conf get g.foo
@@ -33,7 +33,7 @@ setup_inner() {
eq '${#lines[*]}' 0
app conf
- eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${lines[0]}' "app.bin bin/app-a"
eq '${#lines[*]}' 1
}
@@ -42,13 +42,13 @@ setup_inner() {
app conf
eq '${#lines[*]}' 1
- eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${lines[0]}' "app.bin bin/app-a"
}
@test "./app conf wat" {
check_status=no
app conf wat
- eq '${lines[0]}' "Unknown command: wat"
+ eq '${lines[0]}' "Unknown command: wat"
}
@test "./app conf list" {
@@ -56,11 +56,11 @@ setup_inner() {
app conf
eq '${#lines[*]}' 1
- eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${lines[0]}' "app.bin bin/app-a"
app conf list
eq '${#lines[*]}' 1
- eq '${lines[0]}' "app.bin bin/app-a "
+ eq '${lines[0]}' "app.bin bin/app-a"
check_status=no
app conf list foo
@@ -72,7 +72,7 @@ setup_inner() {
echo "foo.bar=awesome" >> .app/config
app conf list
- eq '${lines[0]}' "foo.bar awesome "
+ eq '${lines[0]}' "foo.bar awesome"
eq '${#lines[*]}' 1
}
@@ -98,16 +98,27 @@ setup_inner() {
eq '${#lines[*]}' 0
app conf
- eq '${lines[0]}' "app.bin bin/app-a "
- eq '${lines[1]}' "group.foo bar "
+ eq '${lines[0]}' "app.bin bin/app-a"
+ eq '${lines[1]}' "group.foo bar"
eq '${#lines[*]}' 2
}
+@test "./app conf set - values with '=' and spaces" {
+ echo > .app/config
+ app conf set app.env "JAVA_OPTS=-Xmx1G -Dawesome=true"
+ app_libexec app-cat-conf
+ eq '${lines[0]}' "app.env=JAVA_OPTS=-Xmx1G -Dawesome=true"
+ eq '${#lines[*]}' 1
+ app conf get app.env
+ eq '${lines[0]}' "JAVA_OPTS=-Xmx1G -Dawesome=true"
+ eq '${#lines[*]}' 1
+}
+
@test "./app conf -l app set" {
echo > .app/config
app conf -l app set a.x 2
app_libexec app-cat-conf
- eq '${lines[0]}' "a.x=2"
+ eq '${lines[0]}' "a.x=2"
eq '${#lines[*]}' 1
}
@@ -115,7 +126,7 @@ setup_inner() {
echo > .app/config
app conf -l user set a.x 3
app_libexec app-cat-conf -l user
- eq '${lines[0]}' "a.x=3"
+ eq '${lines[0]}' "a.x=3"
eq '${#lines[*]}' 1
}
@@ -125,11 +136,11 @@ setup_inner() {
echo "foo.bar=2" >> config-b
app conf import config-b
- eq '${lines[0]}' "Importing config from config-b"
+ eq '${lines[0]}' "Importing config from config-b"
eq '${#lines[*]}' 1
app_libexec app-cat-conf
- eq '${lines[0]}' "foo.bar=2"
- eq '${lines[1]}' "foo.baz=1"
+ eq '${lines[0]}' "foo.bar=2"
+ eq '${lines[1]}' "foo.baz=1"
eq '${#lines[*]}' 2
}
diff --git a/test/utils.bash b/test/utils.bash
index f767d90..9979404 100644
--- a/test/utils.bash
+++ b/test/utils.bash
@@ -8,10 +8,10 @@ exit_usage_wrong=0
setup() {
find test/data -name \*.zip | xargs rm -f
+ APPSH_HOME=$(cd $BATS_TEST_DIRNAME/..; echo `pwd`)
ORIG_PATH=$PATH
PATH=/bin:/usr/bin
PATH=$PATH:$APPSH_HOME
- APPSH_HOME=$(cd $BATS_TEST_DIRNAME/..; echo `pwd`)
rm -rf $BATS_TMPDIR/app.sh
mkdir $BATS_TMPDIR/app.sh
@@ -58,7 +58,7 @@ check_status=yes
app() {
echo app $@
- run $APPSH_HOME/app $@
+ run $APPSH_HOME/app "$@"
echo_lines
if [ "$check_status" = yes ]
@@ -74,7 +74,7 @@ app_libexec() {
echo libexec/$@
shift
- run "$x" $@
+ run "$x" "$@"
echo_lines