mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[enh] helpers: allow to get/set/delete app settings without explicitly passing app id everytime...
This commit is contained in:
parent
974ea71fc8
commit
fcd2ef9d20
2 changed files with 35 additions and 0 deletions
|
@ -8,6 +8,7 @@
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 2.2.4 or higher.
|
# Requires YunoHost version 2.2.4 or higher.
|
||||||
ynh_app_setting_get() {
|
ynh_app_setting_get() {
|
||||||
|
local _globalapp=${app-:}
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=ak
|
local legacy_args=ak
|
||||||
local -A args_array=([a]=app= [k]=key=)
|
local -A args_array=([a]=app= [k]=key=)
|
||||||
|
@ -15,6 +16,7 @@ ynh_app_setting_get() {
|
||||||
local key
|
local key
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
app="${app:-$_globalapp}"
|
||||||
|
|
||||||
if [[ $key =~ (unprotected|protected|skipped)_ ]]; then
|
if [[ $key =~ (unprotected|protected|skipped)_ ]]; then
|
||||||
yunohost app setting $app $key
|
yunohost app setting $app $key
|
||||||
|
@ -32,6 +34,7 @@ ynh_app_setting_get() {
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 2.2.4 or higher.
|
# Requires YunoHost version 2.2.4 or higher.
|
||||||
ynh_app_setting_set() {
|
ynh_app_setting_set() {
|
||||||
|
local _globalapp=${app-:}
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=akv
|
local legacy_args=akv
|
||||||
local -A args_array=([a]=app= [k]=key= [v]=value=)
|
local -A args_array=([a]=app= [k]=key= [v]=value=)
|
||||||
|
@ -40,6 +43,7 @@ ynh_app_setting_set() {
|
||||||
local value
|
local value
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
app="${app:-$_globalapp}"
|
||||||
|
|
||||||
if [[ $key =~ (unprotected|protected|skipped)_ ]]; then
|
if [[ $key =~ (unprotected|protected|skipped)_ ]]; then
|
||||||
yunohost app setting $app $key -v $value
|
yunohost app setting $app $key -v $value
|
||||||
|
@ -56,6 +60,7 @@ ynh_app_setting_set() {
|
||||||
#
|
#
|
||||||
# Requires YunoHost version 2.2.4 or higher.
|
# Requires YunoHost version 2.2.4 or higher.
|
||||||
ynh_app_setting_delete() {
|
ynh_app_setting_delete() {
|
||||||
|
local _globalapp=${app-:}
|
||||||
# Declare an array to define the options of this helper.
|
# Declare an array to define the options of this helper.
|
||||||
local legacy_args=ak
|
local legacy_args=ak
|
||||||
local -A args_array=([a]=app= [k]=key=)
|
local -A args_array=([a]=app= [k]=key=)
|
||||||
|
@ -63,6 +68,7 @@ ynh_app_setting_delete() {
|
||||||
local key
|
local key
|
||||||
# Manage arguments with getopts
|
# Manage arguments with getopts
|
||||||
ynh_handle_getopts_args "$@"
|
ynh_handle_getopts_args "$@"
|
||||||
|
app="${app:-$_globalapp}"
|
||||||
|
|
||||||
if [[ "$key" =~ (unprotected|skipped|protected)_ ]]; then
|
if [[ "$key" =~ (unprotected|skipped|protected)_ ]]; then
|
||||||
yunohost app setting $app $key -d
|
yunohost app setting $app $key -d
|
||||||
|
|
29
tests/test_helpers.d/ynhtest_settings.sh
Normal file
29
tests/test_helpers.d/ynhtest_settings.sh
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
ynhtest_settings() {
|
||||||
|
|
||||||
|
test -n "$app"
|
||||||
|
|
||||||
|
mkdir -p "/etc/yunohost/apps/$app"
|
||||||
|
echo "label: $app" > "/etc/yunohost/apps/$app/settings.yml"
|
||||||
|
|
||||||
|
test -z "$(ynh_app_setting_get --key="foo")"
|
||||||
|
test -z "$(ynh_app_setting_get --key="bar")"
|
||||||
|
test -z "$(ynh_app_setting_get --app="$app" --key="baz")"
|
||||||
|
|
||||||
|
ynh_app_setting_set --key="foo" --value="foovalue"
|
||||||
|
ynh_app_setting_set --app="$app" --key="bar" --value="barvalue"
|
||||||
|
ynh_app_setting_set "$app" baz bazvalue
|
||||||
|
|
||||||
|
test "$(ynh_app_setting_get --key="foo")" == "foovalue"
|
||||||
|
test "$(ynh_app_setting_get --key="bar")" == "barvalue"
|
||||||
|
test "$(ynh_app_setting_get --app="$app" --key="baz")" == "bazvalue"
|
||||||
|
|
||||||
|
ynh_app_setting_delete --key="foo"
|
||||||
|
ynh_app_setting_delete --app="$app" --key="bar"
|
||||||
|
ynh_app_setting_delete "$app" baz
|
||||||
|
|
||||||
|
test -z "$(ynh_app_setting_get --key="foo")"
|
||||||
|
test -z "$(ynh_app_setting_get --key="bar")"
|
||||||
|
test -z "$(ynh_app_setting_get --app="$app" --key="baz")"
|
||||||
|
|
||||||
|
rm -rf "/etc/yunohost/apps/$app"
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue